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 namespace CSMWorld
{ {
enum TableEditModes
{
TableEdit_None, // no editing
TableEdit_Full, // edit cells and add/remove rows
TableEdit_FixedRows // edit cells only
};
struct ColumnBase struct ColumnBase
{ {
enum Roles enum Roles
@ -190,8 +197,8 @@ namespace CSMWorld
template<typename ESXRecordT> template<typename ESXRecordT>
struct NestedParentColumn : public Column<ESXRecordT> struct NestedParentColumn : public Column<ESXRecordT>
{ {
NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue) : Column<ESXRecordT> (id, NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue, bool fixedRows = false)
ColumnBase::Display_NestedHeader, flags) : Column<ESXRecordT> (id, ColumnBase::Display_NestedHeader, flags), mFixedRows(fixedRows)
{} {}
virtual void set (Record<ESXRecordT>& record, const QVariant& data) virtual void set (Record<ESXRecordT>& record, const QVariant& data)
@ -202,13 +209,20 @@ namespace CSMWorld
virtual QVariant get (const Record<ESXRecordT>& record) const 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 virtual bool isEditable() const
{ {
return true; return true;
} }
Private:
bool mFixedRows;
}; };
struct NestedChildColumn : public NestableColumn struct NestedChildColumn : public NestableColumn
@ -223,4 +237,6 @@ namespace CSMWorld
}; };
} }
Q_DECLARE_METATYPE(CSMWorld::TableEditModes)
#endif #endif

@ -136,7 +136,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRaces.getNestableColumn(index)->addColumn( mRaces.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SpellId, ColumnBase::Display_Spell)); new NestedChildColumn (Columns::ColumnId_SpellId, ColumnBase::Display_Spell));
// Race attributes // 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; index = mRaces.getColumns()-1;
mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceAttributeAdapter())); mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceAttributeAdapter()));
mRaces.getNestableColumn(index)->addColumn( mRaces.getNestableColumn(index)->addColumn(
@ -147,7 +148,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRaces.getNestableColumn(index)->addColumn( mRaces.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Female, ColumnBase::Display_Integer)); new NestedChildColumn (Columns::ColumnId_Female, ColumnBase::Display_Integer));
// Race skill bonus // 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; index = mRaces.getColumns()-1;
mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceSkillsBonusAdapter())); mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new RaceSkillsBonusAdapter()));
mRaces.getNestableColumn(index)->addColumn( mRaces.getNestableColumn(index)->addColumn(

@ -25,8 +25,9 @@ QVariant CSMWorld::PotionRefIdAdapter::getData (const RefIdColumn *column, const
if (column==mAutoCalc) if (column==mAutoCalc)
return record.get().mData.mAutoCalc!=0; return record.get().mData.mAutoCalc!=0;
// to show nested tables in dialogue subview, see IdTree::hasChildren()
if (column==mColumns.mEffects) 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); 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))); data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Ingredient)));
if (column==mColumns.mEffects) 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); return InventoryRefIdAdapter<ESM::Ingredient>::getData (column, data, index);
} }
@ -271,7 +272,7 @@ QVariant CSMWorld::ArmorRefIdAdapter::getData (const RefIdColumn *column,
return record.get().mData.mArmor; return record.get().mData.mArmor;
if (column==mPartRef) 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); return EnchantableRefIdAdapter<ESM::Armor>::getData (column, data, index);
} }
@ -359,7 +360,7 @@ QVariant CSMWorld::ClothingRefIdAdapter::getData (const RefIdColumn *column,
return record.get().mData.mType; return record.get().mData.mType;
if (column==mPartRef) 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); 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; return (record.get().mFlags & ESM::Container::Respawn)!=0;
if (column==mContent) 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); 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()); return QString::fromUtf8 (record.get().mOriginal.c_str());
if (column==mColumns.mAttributes) if (column==mColumns.mAttributes)
return true; // Required to show nested tables in dialogue subview return QVariant::fromValue(TableEditModes::TableEdit_FixedRows);
if (column==mColumns.mAttacks) if (column==mColumns.mAttacks)
return true; // Required to show nested tables in dialogue subview return QVariant::fromValue(TableEditModes::TableEdit_FixedRows);
if (column==mColumns.mMisc) 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 = std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
mColumns.mFlags.find (column); 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 (column==mColumns.mAttributes || column==mColumns.mSkills)
{ {
if ((record.get().mFlags & ESM::NPC::Autocalc) != 0) if ((record.get().mFlags & ESM::NPC::Autocalc) != 0)
return QVariant(QVariant::UserType); return QVariant::fromValue(TableEditModes::TableEdit_None);
else else
return true; return QVariant::fromValue(TableEditModes::TableEdit_FixedRows);
} }
if (column==mColumns.mMisc) if (column==mColumns.mMisc)
return true; return QVariant::fromValue(TableEditModes::TableEdit_Full);
std::map<const RefIdColumn *, unsigned int>::const_iterator iter = std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
mColumns.mFlags.find (column); 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()), static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (row, typeColumn)).toInt()),
mTable->data (mTable->index (row, idColumn)).toString().toUtf8().constData()); mTable->data (mTable->index (row, idColumn)).toString().toUtf8().constData());
NestedTable* table = new NestedTable(mDocument, id, mNestedModels.back(), this); bool editable = true;
table->resizeColumnsToContents(); bool fixedRows = false;
QVariant v = mTable->index(row, i).data();
if (v.canConvert<CSMWorld::TableEditModes>())
{
assert (QString(v.typeName()) == "CSMWorld::TableEditModes");
if(mTable->index(row, i).data().type() == QVariant::UserType) 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); table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setEnabled(false); table->setEnabled(false);
@ -583,7 +594,7 @@ void CSVWorld::EditWidget::remake(int row)
new QLabel (mTable->headerData (i, Qt::Horizontal, Qt::DisplayRole).toString(), mMainWidget); new QLabel (mTable->headerData (i, Qt::Horizontal, Qt::DisplayRole).toString(), mMainWidget);
label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
if(mTable->index(row, i).data().type() == QVariant::UserType) if(!editable)
label->setEnabled(false); label->setEnabled(false);
tablesLayout->addWidget(label); tablesLayout->addWidget(label);

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

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

Loading…
Cancel
Save