Disable context menu for fixed size sub-tables. Should resolve bug #2932.

openmw-37
cc9cii 9 years ago
parent 972193c7eb
commit 80869d9bae

@ -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

@ -136,7 +136,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(
@ -147,7 +148,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(

@ -25,8 +25,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);
}
@ -67,7 +68,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);
}
@ -271,7 +272,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);
}
@ -359,7 +360,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);
}
@ -407,7 +408,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);
}
@ -476,13 +477,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);
@ -722,13 +723,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);

@ -564,10 +564,21 @@ 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());
NestedTable* table = new NestedTable(mDocument, id, mNestedModels.back(), this);
table->resizeColumnsToContents();
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;
}
if(mTable->index(row, i).data().type() == QVariant::UserType)
NestedTable* table = new NestedTable(mDocument, id, mNestedModels.back(), this, editable, fixedRows);
if (!editable)
{
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setEnabled(false);
@ -583,7 +594,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);

@ -16,8 +16,13 @@
CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
CSMWorld::UniversalId id,
CSMWorld::NestedTableProxyModel* model,
QWidget* parent)
QWidget* parent,
bool editable,
bool fixedRows)
: DragRecordTable(document, parent),
mAddNewRowAction(NULL),
mRemoveRowAction(NULL),
mEditIdAction(NULL),
mModel(model)
{
mDispatcher = new CSMWorld::CommandDispatcher (document, id, this);
@ -49,18 +54,24 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
setModel(model);
mAddNewRowAction = new QAction (tr ("Add new row"), this);
if (editable)
{
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()));
mEditIdAction = new TableEditIdAction(*this, this);
connect(mEditIdAction, SIGNAL(triggered()), this, SLOT(editCell()));
}
}
std::vector<CSMWorld::UniversalId> CSVWorld::NestedTable::getDraggedRecords() const
@ -71,6 +82,9 @@ std::vector<CSMWorld::UniversalId> CSVWorld::NestedTable::getDraggedRecords() co
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
{
if (!mEditIdAction)
return;
QModelIndexList selectedRows = selectionModel()->selectedRows();
QMenu menu(this);
@ -84,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());
}

@ -38,7 +38,9 @@ namespace CSVWorld
NestedTable(CSMDoc::Document& document,
CSMWorld::UniversalId id,
CSMWorld::NestedTableProxyModel* model,
QWidget* parent = NULL);
QWidget* parent = NULL,
bool editable = true,
bool fixedRows = false);
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;

Loading…
Cancel
Save