diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index a655b96b3..83880cbce 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -47,14 +47,6 @@ Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : default //INIT_OBJ_TYPE(CGSeerHut); } -bool stringToBool(const QString & s) -{ - if(s == "TRUE") - return true; - //if(s == "FALSE") - return false; -} - void Initializer::initialize(CArmedInstance * o) { if(!o) return; @@ -236,7 +228,7 @@ void Inspector::updateProperties(CGGarrison * o) if(!o) return; addProperty("Owner", o->tempOwner, false); - addProperty("Removable units", o->removableUnits, InspectorDelegate::boolDelegate(), false); + addProperty("Removable units", o->removableUnits, false); } void Inspector::updateProperties(CGShipyard * o) @@ -345,8 +337,8 @@ void Inspector::updateProperties(CGCreature * o) delegate->options << "COMPLIANT" << "FRIENDLY" << "AGRESSIVE" << "HOSTILE" << "SAVAGE"; addProperty("Character", (CGCreature::Character)o->character, delegate, false); } - addProperty("Never flees", o->neverFlees, InspectorDelegate::boolDelegate(), false); - addProperty("Not growing", o->notGrowingTeam, InspectorDelegate::boolDelegate(), false); + addProperty("Never flees", o->neverFlees, false); + addProperty("Not growing", o->notGrowingTeam, false); addProperty("Artifact reward", o->gainedArtifact); //TODO: implement in setProperty addProperty("Army", PropertyEditorPlaceholder(), true); addProperty("Amount", o->stacks[SlotID(0)]->count, false); @@ -367,9 +359,9 @@ void Inspector::updateProperties(CGEvent * o) { if(!o) return; - addProperty("Remove after", o->removeAfterVisit, InspectorDelegate::boolDelegate(), false); - addProperty("Human trigger", o->humanActivate, InspectorDelegate::boolDelegate(), false); - addProperty("Cpu trigger", o->computerActivate, InspectorDelegate::boolDelegate(), false); + addProperty("Remove after", o->removeAfterVisit, false); + addProperty("Human trigger", o->humanActivate, false); + addProperty("Cpu trigger", o->computerActivate, false); //ui8 availableFor; //players whom this event is available for } @@ -499,13 +491,13 @@ void Inspector::setProperty(CGEvent * o, const QString & key, const QVariant & v if(!o) return; if(key == "Remove after") - o->removeAfterVisit = stringToBool(value.toString()); + o->removeAfterVisit = value.toBool(); if(key == "Human trigger") - o->humanActivate = stringToBool(value.toString()); + o->humanActivate = value.toBool(); if(key == "Cpu trigger") - o->computerActivate = stringToBool(value.toString()); + o->computerActivate = value.toBool(); } void Inspector::setProperty(CGTownInstance * o, const QString & key, const QVariant & value) @@ -562,7 +554,7 @@ void Inspector::setProperty(CGGarrison * o, const QString & key, const QVariant if(!o) return; if(key == "Removable units") - o->removableUnits = stringToBool(value.toString()); + o->removableUnits = value.toBool(); } void Inspector::setProperty(CGHeroInstance * o, const QString & key, const QVariant & value) @@ -626,9 +618,9 @@ void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant o->character = CGCreature::Character::SAVAGE; } if(key == "Never flees") - o->neverFlees = stringToBool(value.toString()); + o->neverFlees = value.toBool(); if(key == "Not growing") - o->notGrowingTeam = stringToBool(value.toString()); + o->notGrowingTeam = value.toBool(); if(key == "Amount") o->stacks[SlotID(0)]->count = value.toString().toInt(); } @@ -693,7 +685,10 @@ QTableWidgetItem * Inspector::addProperty(int value) QTableWidgetItem * Inspector::addProperty(bool value) { - return new QTableWidgetItem(value ? "TRUE" : "FALSE"); + auto item = new QTableWidgetItem; + item->setFlags(item->flags() & ~Qt::ItemIsEditable | Qt::ItemIsUserCheckable); + item->setCheckState(value ? Qt::Checked : Qt::Unchecked); + return item; } QTableWidgetItem * Inspector::addProperty(const std::string & value) @@ -827,13 +822,6 @@ Inspector::Inspector(CMap * m, CGObjectInstance * o, QTableWidget * t): obj(o), * Delegates */ -InspectorDelegate * InspectorDelegate::boolDelegate() -{ - auto * d = new InspectorDelegate; - d->options << "TRUE" << "FALSE"; - return d; -} - QWidget * InspectorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { return new QComboBox(parent); diff --git a/mapeditor/inspector/inspector.h b/mapeditor/inspector/inspector.h index 4a1526518..6ee27b4f7 100644 --- a/mapeditor/inspector/inspector.h +++ b/mapeditor/inspector/inspector.h @@ -107,7 +107,8 @@ protected: { auto * itemValue = addProperty(value); if(restricted) - itemValue->setFlags(Qt::NoItemFlags); + itemValue->setFlags(itemValue->flags() & ~Qt::ItemIsEnabled); + //itemValue->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable); QTableWidgetItem * itemKey = nullptr; if(keyItems.contains(key)) @@ -120,7 +121,6 @@ protected: else { itemKey = new QTableWidgetItem(key); - itemKey->setFlags(Qt::NoItemFlags); keyItems[key] = itemKey; table->setRowCount(row + 1); @@ -130,6 +130,7 @@ protected: table->setItemDelegateForRow(row, delegate); ++row; } + itemKey->setFlags(restricted ? Qt::NoItemFlags : Qt::ItemIsEnabled); } template @@ -153,8 +154,6 @@ class InspectorDelegate : public QStyledItemDelegate { Q_OBJECT public: - static InspectorDelegate * boolDelegate(); - using QStyledItemDelegate::QStyledItemDelegate; QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 5788fb577..f838f519b 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -1015,7 +1015,10 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item) //set parameter Inspector inspector(controller.map(), obj, tableWidget); - inspector.setProperty(param, item->text()); + if(item->flags() & Qt::ItemIsUserCheckable) + inspector.setProperty(param, QVariant::fromValue(item->checkState() == Qt::Checked)); + else + inspector.setProperty(param, item->text()); controller.commitObjectChange(mapLevel); } diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 7247dcf7c..159a1ec98 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -390,6 +390,9 @@ 2 + + true + false