mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	Disable context menu for fixed size sub-tables. Should resolve bug #2932.
(cherry picked from commit 80869d9bae)
Conflicts:
	apps/opencs/view/world/dialoguesubview.cpp
	apps/opencs/view/world/nestedtable.cpp
	apps/opencs/view/world/nestedtable.hpp
			
			
This commit is contained in:
		
							parent
							
								
									b595f2641c
								
							
						
					
					
						commit
						f08680ebcd
					
				
					 6 changed files with 81 additions and 40 deletions
				
			
		|  | @ -12,6 +12,13 @@ | |||
| 
 | ||||
| namespace CSMWorld | ||||
| { | ||||
|     enum TableEditModes | ||||
|     { | ||||
|         TableEdit_None,      // no editing
 | ||||
|         TableEdit_Full,      // edit cells and add/remove rows
 | ||||
|         TableEdit_FixedRows  // edit cells only
 | ||||
|     }; | ||||
| 
 | ||||
|     struct ColumnBase | ||||
|     { | ||||
|         enum Roles | ||||
|  | @ -190,8 +197,8 @@ namespace CSMWorld | |||
|     template<typename ESXRecordT> | ||||
|     struct NestedParentColumn : public Column<ESXRecordT> | ||||
|     { | ||||
|         NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue) : Column<ESXRecordT> (id, | ||||
|                 ColumnBase::Display_NestedHeader, flags) | ||||
|         NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue, bool fixedRows = false) | ||||
|             : Column<ESXRecordT> (id, ColumnBase::Display_NestedHeader, flags), mFixedRows(fixedRows) | ||||
|         {} | ||||
| 
 | ||||
|         virtual void set (Record<ESXRecordT>& record, const QVariant& data) | ||||
|  | @ -202,13 +209,20 @@ namespace CSMWorld | |||
| 
 | ||||
|         virtual QVariant get (const Record<ESXRecordT>& record) const | ||||
|         { | ||||
|             return true; // required by IdTree::hasChildren()
 | ||||
|             // by default editable; also see IdTree::hasChildren()
 | ||||
|             if (mFixedRows) | ||||
|                 return QVariant::fromValue(TableEditModes::TableEdit_FixedRows); | ||||
|             else | ||||
|                 return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
|         } | ||||
| 
 | ||||
|         virtual bool isEditable() const | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|     Private: | ||||
|         bool mFixedRows; | ||||
|     }; | ||||
| 
 | ||||
|     struct NestedChildColumn : public NestableColumn | ||||
|  | @ -223,4 +237,6 @@ namespace CSMWorld | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| Q_DECLARE_METATYPE(CSMWorld::TableEditModes) | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -205,7 +205,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc | |||
|     mRaces.getNestableColumn(index)->addColumn( | ||||
|         new NestedChildColumn (Columns::ColumnId_SpellId, ColumnBase::Display_Spell)); | ||||
|     // Race attributes
 | ||||
|     mRaces.addColumn (new NestedParentColumn<ESM::Race> (Columns::ColumnId_RaceAttributes)); | ||||
|     mRaces.addColumn (new NestedParentColumn<ESM::Race> (Columns::ColumnId_RaceAttributes, | ||||
|         ColumnBase::Flag_Dialogue, true)); // fixed rows table
 | ||||
|     index = mRaces.getColumns()-1; | ||||
|     mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceAttributeAdapter())); | ||||
|     mRaces.getNestableColumn(index)->addColumn( | ||||
|  | @ -216,7 +217,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc | |||
|     mRaces.getNestableColumn(index)->addColumn( | ||||
|         new NestedChildColumn (Columns::ColumnId_Female, ColumnBase::Display_Integer)); | ||||
|     // Race skill bonus
 | ||||
|     mRaces.addColumn (new NestedParentColumn<ESM::Race> (Columns::ColumnId_RaceSkillBonus)); | ||||
|     mRaces.addColumn (new NestedParentColumn<ESM::Race> (Columns::ColumnId_RaceSkillBonus, | ||||
|         ColumnBase::Flag_Dialogue, true)); // fixed rows table
 | ||||
|     index = mRaces.getColumns()-1; | ||||
|     mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceSkillsBonusAdapter())); | ||||
|     mRaces.getNestableColumn(index)->addColumn( | ||||
|  |  | |||
|  | @ -30,8 +30,9 @@ QVariant CSMWorld::PotionRefIdAdapter::getData (const RefIdColumn *column, const | |||
|     if (column==mAutoCalc) | ||||
|         return record.get().mData.mAutoCalc!=0; | ||||
| 
 | ||||
|     // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|     if (column==mColumns.mEffects) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     return InventoryRefIdAdapter<ESM::Potion>::getData (column, data, index); | ||||
| } | ||||
|  | @ -72,7 +73,7 @@ QVariant CSMWorld::IngredientRefIdAdapter::getData (const RefIdColumn *column, c | |||
|         data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Ingredient))); | ||||
| 
 | ||||
|     if (column==mColumns.mEffects) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_FixedRows); | ||||
| 
 | ||||
|     return InventoryRefIdAdapter<ESM::Ingredient>::getData (column, data, index); | ||||
| } | ||||
|  | @ -276,7 +277,7 @@ QVariant CSMWorld::ArmorRefIdAdapter::getData (const RefIdColumn *column, | |||
|         return record.get().mData.mArmor; | ||||
| 
 | ||||
|     if (column==mPartRef) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     return EnchantableRefIdAdapter<ESM::Armor>::getData (column, data, index); | ||||
| } | ||||
|  | @ -364,7 +365,7 @@ QVariant CSMWorld::ClothingRefIdAdapter::getData (const RefIdColumn *column, | |||
|         return record.get().mData.mType; | ||||
| 
 | ||||
|     if (column==mPartRef) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     return EnchantableRefIdAdapter<ESM::Clothing>::getData (column, data, index); | ||||
| } | ||||
|  | @ -412,7 +413,7 @@ QVariant CSMWorld::ContainerRefIdAdapter::getData (const RefIdColumn *column, | |||
|         return (record.get().mFlags & ESM::Container::Respawn)!=0; | ||||
| 
 | ||||
|     if (column==mContent) | ||||
|         return true; // Required to show nested tables in dialogue subview
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     return NameRefIdAdapter<ESM::Container>::getData (column, data, index); | ||||
| } | ||||
|  | @ -481,13 +482,13 @@ QVariant CSMWorld::CreatureRefIdAdapter::getData (const RefIdColumn *column, con | |||
|         return QString::fromUtf8 (record.get().mOriginal.c_str()); | ||||
| 
 | ||||
|     if (column==mColumns.mAttributes) | ||||
|         return true; // Required to show nested tables in dialogue subview
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_FixedRows); | ||||
| 
 | ||||
|     if (column==mColumns.mAttacks) | ||||
|         return true; // Required to show nested tables in dialogue subview
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_FixedRows); | ||||
| 
 | ||||
|     if (column==mColumns.mMisc) | ||||
|         return true; // Required to show nested items in dialogue subview
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     std::map<const RefIdColumn *, unsigned int>::const_iterator iter = | ||||
|         mColumns.mFlags.find (column); | ||||
|  | @ -727,13 +728,13 @@ QVariant CSMWorld::NpcRefIdAdapter::getData (const RefIdColumn *column, const Re | |||
|     if (column==mColumns.mAttributes || column==mColumns.mSkills) | ||||
|     { | ||||
|         if ((record.get().mFlags & ESM::NPC::Autocalc) != 0) | ||||
|             return QVariant(QVariant::UserType); | ||||
|             return QVariant::fromValue(TableEditModes::TableEdit_None); | ||||
|         else | ||||
|             return true; | ||||
|             return QVariant::fromValue(TableEditModes::TableEdit_FixedRows); | ||||
|     } | ||||
| 
 | ||||
|     if (column==mColumns.mMisc) | ||||
|         return true; | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     std::map<const RefIdColumn *, unsigned int>::const_iterator iter = | ||||
|         mColumns.mFlags.find (column); | ||||
|  | @ -1613,21 +1614,21 @@ QVariant ActorRefIdAdapter<ESM::NPC>::getData (const RefIdColumn *column, const | |||
|         return record.get().mAiData.mAlarm; | ||||
| 
 | ||||
|     if (column==mActors.mInventory) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     if (column==mActors.mSpells) | ||||
|     { | ||||
|         if ((record.get().mFlags & ESM::NPC::Autocalc) != 0) | ||||
|             return QVariant(QVariant::UserType); | ||||
|             return QVariant::fromValue(TableEditModes::TableEdit_None); | ||||
|         else | ||||
|             return true; | ||||
|             return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
|     } | ||||
| 
 | ||||
|     if (column==mActors.mDestinations) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     if (column==mActors.mAiPackages) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     std::map<const RefIdColumn *, unsigned int>::const_iterator iter = | ||||
|         mActors.mServices.find (column); | ||||
|  | @ -1794,16 +1795,16 @@ QVariant ActorRefIdAdapter<ESM::Creature>::getData (const RefIdColumn *column, c | |||
|         return record.get().mAiData.mAlarm; | ||||
| 
 | ||||
|     if (column==mActors.mInventory) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     if (column==mActors.mSpells) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     if (column==mActors.mDestinations) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     if (column==mActors.mAiPackages) | ||||
|         return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
 | ||||
|         return QVariant::fromValue(TableEditModes::TableEdit_Full); | ||||
| 
 | ||||
|     std::map<const RefIdColumn *, unsigned int>::const_iterator iter = | ||||
|         mActors.mServices.find (column); | ||||
|  |  | |||
|  | @ -564,8 +564,20 @@ void CSVWorld::EditWidget::remake(int row) | |||
|                     static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (row, typeColumn)).toInt()), | ||||
|                     mTable->data (mTable->index (row, idColumn)).toString().toUtf8().constData()); | ||||
| 
 | ||||
|                 bool editable = mTable->index(row, i).data().type() != QVariant::UserType; | ||||
|                 NestedTable* table = new NestedTable(mDocument, id, mNestedModels.back(), this, editable); | ||||
|                 bool editable = true; | ||||
|                 bool fixedRows = false; | ||||
|                 QVariant v = mTable->index(row, i).data(); | ||||
|                 if (v.canConvert<CSMWorld::TableEditModes>()) | ||||
|                 { | ||||
|                     assert (QString(v.typeName()) == "CSMWorld::TableEditModes"); | ||||
| 
 | ||||
|                     if (v.value<CSMWorld::TableEditModes>() == CSMWorld::TableEditModes::TableEdit_None) | ||||
|                         editable = false; | ||||
|                     else if (v.value<CSMWorld::TableEditModes>() == CSMWorld::TableEditModes::TableEdit_FixedRows) | ||||
|                         fixedRows = true; | ||||
|                 } | ||||
| 
 | ||||
|                 NestedTable* table = new NestedTable(mDocument, id, mNestedModels.back(), this, editable, fixedRows); | ||||
|                 if (!editable) | ||||
|                 { | ||||
|                     table->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||||
|  | @ -588,7 +600,7 @@ void CSVWorld::EditWidget::remake(int row) | |||
|                     new QLabel (mTable->headerData (i, Qt::Horizontal, Qt::DisplayRole).toString(), mMainWidget); | ||||
| 
 | ||||
|                 label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); | ||||
|                 if(mTable->index(row, i).data().type() == QVariant::UserType) | ||||
|                 if(!editable) | ||||
|                     label->setEnabled(false); | ||||
| 
 | ||||
|                 tablesLayout->addWidget(label); | ||||
|  |  | |||
|  | @ -17,9 +17,12 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document, | |||
|                                    CSMWorld::UniversalId id, | ||||
|                                    CSMWorld::NestedTableProxyModel* model, | ||||
|                                    QWidget* parent, | ||||
|                                    bool editable) | ||||
|                                    bool editable, | ||||
|                                    bool fixedRows) | ||||
|     : DragRecordTable(document, parent), | ||||
|       mEditIdAction(0), | ||||
|       mAddNewRowAction(NULL), | ||||
|       mRemoveRowAction(NULL), | ||||
|       mEditIdAction(NULL), | ||||
|       mModel(model) | ||||
| { | ||||
|     mDispatcher = new CSMWorld::CommandDispatcher (document, id, this); | ||||
|  | @ -53,15 +56,18 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document, | |||
| 
 | ||||
|     if (editable) | ||||
|     { | ||||
|         mAddNewRowAction = new QAction (tr ("Add new row"), this); | ||||
|         if (!fixedRows) | ||||
|         { | ||||
|             mAddNewRowAction = new QAction (tr ("Add new row"), this); | ||||
| 
 | ||||
|         connect(mAddNewRowAction, SIGNAL(triggered()), | ||||
|                 this, SLOT(addNewRowActionTriggered())); | ||||
|             connect(mAddNewRowAction, SIGNAL(triggered()), | ||||
|                     this, SLOT(addNewRowActionTriggered())); | ||||
| 
 | ||||
|         mRemoveRowAction = new QAction (tr ("Remove row"), this); | ||||
|             mRemoveRowAction = new QAction (tr ("Remove row"), this); | ||||
| 
 | ||||
|         connect(mRemoveRowAction, SIGNAL(triggered()), | ||||
|                 this, SLOT(removeRowActionTriggered())); | ||||
|             connect(mRemoveRowAction, SIGNAL(triggered()), | ||||
|                     this, SLOT(removeRowActionTriggered())); | ||||
|         } | ||||
| 
 | ||||
|         mEditIdAction = new TableEditIdAction(*this, this); | ||||
|         connect(mEditIdAction, SIGNAL(triggered()), this, SLOT(editCell())); | ||||
|  | @ -92,10 +98,13 @@ void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event) | |||
|         menu.addSeparator(); | ||||
|     } | ||||
| 
 | ||||
|     if (selectionModel()->selectedRows().size() == 1) | ||||
|         menu.addAction(mRemoveRowAction); | ||||
|     if (mAddNewRowAction && mRemoveRowAction) | ||||
|     { | ||||
|         if (selectionModel()->selectedRows().size() == 1) | ||||
|             menu.addAction(mRemoveRowAction); | ||||
| 
 | ||||
|     menu.addAction(mAddNewRowAction); | ||||
|         menu.addAction(mAddNewRowAction); | ||||
|     } | ||||
| 
 | ||||
|     menu.exec (event->globalPos()); | ||||
| } | ||||
|  |  | |||
|  | @ -39,7 +39,8 @@ namespace CSVWorld | |||
|                     CSMWorld::UniversalId id, | ||||
|                     CSMWorld::NestedTableProxyModel* model, | ||||
|                     QWidget* parent = NULL, | ||||
|                     bool editable = true); | ||||
|                     bool editable = true, | ||||
|                     bool fixedRows = false); | ||||
| 
 | ||||
|         virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue