1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

Close the extended configurator when all respective records were removed outside

This commit is contained in:
Stanislav Bas 2015-07-05 22:10:37 +03:00
parent ceb3dea55c
commit 3c6bc74062
2 changed files with 42 additions and 2 deletions

View File

@ -1,12 +1,17 @@
#include "extendedcommandconfigurator.hpp" #include "extendedcommandconfigurator.hpp"
#include <algorithm>
#include <QPushButton> #include <QPushButton>
#include <QGroupBox> #include <QGroupBox>
#include <QCheckBox> #include <QCheckBox>
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
#include "../../model/doc/document.hpp"
#include "../../model/world/commanddispatcher.hpp" #include "../../model/world/commanddispatcher.hpp"
#include "../../model/world/data.hpp"
CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Document &document, CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Document &document,
const CSMWorld::UniversalId &id, const CSMWorld::UniversalId &id,
@ -14,10 +19,13 @@ CSVWorld::ExtendedCommandConfigurator::ExtendedCommandConfigurator(CSMDoc::Docum
: QWidget(parent), : QWidget(parent),
mNumUsedCheckBoxes(0), mNumUsedCheckBoxes(0),
mNumChecked(0), mNumChecked(0),
mMode(Mode_None) mMode(Mode_None),
mData(document.getData())
{ {
mCommandDispatcher = new CSMWorld::CommandDispatcher(document, id, this); mCommandDispatcher = new CSMWorld::CommandDispatcher(document, id, this);
connect(&mData, SIGNAL(idListChanged()), this, SLOT(dataIdListChanged()));
mPerformButton = new QPushButton(this); mPerformButton = new QPushButton(this);
mPerformButton->setDefault(true); mPerformButton->setDefault(true);
mPerformButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mPerformButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@ -48,7 +56,8 @@ void CSVWorld::ExtendedCommandConfigurator::configure(CSVWorld::ExtendedCommandC
if (mMode != Mode_None) if (mMode != Mode_None)
{ {
mPerformButton->setText((mMode == Mode_Delete) ? "Extended Delete" : "Extended Revert"); mPerformButton->setText((mMode == Mode_Delete) ? "Extended Delete" : "Extended Revert");
mCommandDispatcher->setSelection(selectedIds); mSelectedIds = selectedIds;
mCommandDispatcher->setSelection(mSelectedIds);
setupCheckBoxes(mCommandDispatcher->getExtendedTypes()); setupCheckBoxes(mCommandDispatcher->getExtendedTypes());
setupGroupLayout(); setupGroupLayout();
} }
@ -177,3 +186,30 @@ void CSVWorld::ExtendedCommandConfigurator::checkBoxStateChanged(int state)
mPerformButton->setEnabled(mNumChecked > 0); mPerformButton->setEnabled(mNumChecked > 0);
} }
void CSVWorld::ExtendedCommandConfigurator::dataIdListChanged()
{
bool idsRemoved = false;
for (int i = 0; i < static_cast<int>(mSelectedIds.size()); ++i)
{
if (!mData.hasId(mSelectedIds[i]))
{
std::swap(mSelectedIds[i], mSelectedIds.back());
mSelectedIds.pop_back();
idsRemoved = true;
--i;
}
}
// If all selected IDs were removed, cancel the configurator
if (mSelectedIds.empty())
{
emit done();
return;
}
if (idsRemoved)
{
mCommandDispatcher->setSelection(mSelectedIds);
}
}

View File

@ -21,6 +21,7 @@ namespace CSMDoc
namespace CSMWorld namespace CSMWorld
{ {
class CommandDispatcher; class CommandDispatcher;
class Data;
} }
namespace CSVWorld namespace CSVWorld
@ -44,6 +45,8 @@ namespace CSVWorld
Mode mMode; Mode mMode;
CSMWorld::CommandDispatcher *mCommandDispatcher; CSMWorld::CommandDispatcher *mCommandDispatcher;
CSMWorld::Data &mData;
std::vector<std::string> mSelectedIds;
void setupGroupLayout(); void setupGroupLayout();
void setupCheckBoxes(const std::vector<CSMWorld::UniversalId> &types); void setupCheckBoxes(const std::vector<CSMWorld::UniversalId> &types);
@ -61,6 +64,7 @@ namespace CSVWorld
private slots: private slots:
void performExtendedCommand(); void performExtendedCommand();
void checkBoxStateChanged(int state); void checkBoxStateChanged(int state);
void dataIdListChanged();
signals: signals:
void done(); void done();