forked from teamnwah/openmw-tes3coop
replaced global world->scene menu item with individual view context menu items in cell and reference tables
This commit is contained in:
parent
6e8b9c88b2
commit
26c2f28879
9 changed files with 99 additions and 23 deletions
|
@ -98,7 +98,7 @@ namespace CSMWorld
|
|||
UniversalId::Type type = UniversalId::Type_None);
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
virtual void cloneRecord(const std::string& origin,
|
||||
virtual void cloneRecord(const std::string& origin,
|
||||
const std::string& destination,
|
||||
const UniversalId::Type type);
|
||||
|
||||
|
@ -198,7 +198,7 @@ namespace CSMWorld
|
|||
}
|
||||
|
||||
template<typename ESXRecordT, typename IdAccessorT>
|
||||
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(const std::string& origin,
|
||||
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(const std::string& origin,
|
||||
const std::string& destination,
|
||||
const UniversalId::Type type)
|
||||
{
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace CSMWorld
|
|||
UniversalId::Type type = UniversalId::Type_None) = 0;
|
||||
///< If the record type does not match, an exception is thrown.
|
||||
|
||||
virtual void cloneRecord(const std::string& origin,
|
||||
virtual void cloneRecord(const std::string& origin,
|
||||
const std::string& destination,
|
||||
const UniversalId::Type type) = 0;
|
||||
|
||||
|
|
|
@ -247,12 +247,12 @@ CSMWorld::Data::Data() : mRefs (mCells)
|
|||
addModel (new IdTable (&mSpells), UniversalId::Type_Spells, UniversalId::Type_Spell);
|
||||
addModel (new IdTable (&mTopics), UniversalId::Type_Topics, UniversalId::Type_Topic);
|
||||
addModel (new IdTable (&mJournals), UniversalId::Type_Journals, UniversalId::Type_Journal);
|
||||
addModel (new IdTable (&mTopicInfos), UniversalId::Type_TopicInfos, UniversalId::Type_TopicInfo);
|
||||
addModel (new IdTable (&mJournalInfos), UniversalId::Type_JournalInfos, UniversalId::Type_JournalInfo);
|
||||
addModel (new IdTable (&mCells), UniversalId::Type_Cells, UniversalId::Type_Cell);
|
||||
addModel (new IdTable (&mTopicInfos, IdTable::Reordering_WithinTopic), UniversalId::Type_TopicInfos, UniversalId::Type_TopicInfo);
|
||||
addModel (new IdTable (&mJournalInfos, IdTable::Reordering_WithinTopic), UniversalId::Type_JournalInfos, UniversalId::Type_JournalInfo);
|
||||
addModel (new IdTable (&mCells, IdTable::Reordering_None, IdTable::Viewing_Id), UniversalId::Type_Cells, UniversalId::Type_Cell);
|
||||
addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables,
|
||||
UniversalId::Type_Referenceable);
|
||||
addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference, false);
|
||||
addModel (new IdTable (&mRefs, IdTable::Reordering_None, IdTable::Viewing_Cell), UniversalId::Type_References, UniversalId::Type_Reference, false);
|
||||
addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
#include "collectionbase.hpp"
|
||||
#include "columnbase.hpp"
|
||||
|
||||
CSMWorld::IdTable::IdTable (CollectionBase *idCollection, Reordering reordering)
|
||||
: mIdCollection (idCollection), mReordering (reordering)
|
||||
CSMWorld::IdTable::IdTable (CollectionBase *idCollection, Reordering reordering,
|
||||
Viewing viewing)
|
||||
: mIdCollection (idCollection), mReordering (reordering), mViewing (viewing)
|
||||
{}
|
||||
|
||||
CSMWorld::IdTable::~IdTable()
|
||||
|
@ -188,4 +189,45 @@ void CSMWorld::IdTable::reorderRows (int baseIndex, const std::vector<int>& newO
|
|||
CSMWorld::IdTable::Reordering CSMWorld::IdTable::getReordering() const
|
||||
{
|
||||
return mReordering;
|
||||
}
|
||||
|
||||
CSMWorld::IdTable::Viewing CSMWorld::IdTable::getViewing() const
|
||||
{
|
||||
return mViewing;
|
||||
}
|
||||
|
||||
std::pair<CSMWorld::UniversalId, std::string> CSMWorld::IdTable::view (int row) const
|
||||
{
|
||||
std::string id;
|
||||
std::string hint;
|
||||
|
||||
if (mViewing==Viewing_Cell)
|
||||
{
|
||||
int cellColumn = mIdCollection->searchColumnIndex (Columns::ColumnId_Cell);
|
||||
int idColumn = mIdCollection->searchColumnIndex (Columns::ColumnId_Id);
|
||||
|
||||
if (cellColumn!=-1 && idColumn!=-1)
|
||||
{
|
||||
id = mIdCollection->getData (row, cellColumn).toString().toUtf8().constData();
|
||||
hint = "r:" + std::string (mIdCollection->getData (row, idColumn).toString().toUtf8().constData());
|
||||
}
|
||||
}
|
||||
else if (mViewing==Viewing_Id)
|
||||
{
|
||||
int column = mIdCollection->searchColumnIndex (Columns::ColumnId_Id);
|
||||
|
||||
if (column!=-1)
|
||||
{
|
||||
id = mIdCollection->getData (row, column).toString().toUtf8().constData();
|
||||
hint = "c:" + id;
|
||||
}
|
||||
}
|
||||
|
||||
if (id.empty())
|
||||
return std::make_pair (UniversalId::Type_None, "");
|
||||
|
||||
if (id[0]=='#')
|
||||
id = "sys::default";
|
||||
|
||||
return std::make_pair (UniversalId (UniversalId::Type_Scene, id), hint);
|
||||
}
|
|
@ -25,10 +25,20 @@ namespace CSMWorld
|
|||
Reordering_WithinTopic
|
||||
};
|
||||
|
||||
enum Viewing
|
||||
{
|
||||
Viewing_None,
|
||||
Viewing_Id, // use ID column to generate view request (ID is transformed into
|
||||
// worldspace and original ID is passed as hint with c: prefix)
|
||||
Viewing_Cell // use cell column to generate view request (cell ID is transformed
|
||||
// into worldspace and record ID is passed as hint with r: prefix)
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
CollectionBase *mIdCollection;
|
||||
Reordering mReordering;
|
||||
Viewing mViewing;
|
||||
|
||||
// not implemented
|
||||
IdTable (const IdTable&);
|
||||
|
@ -36,7 +46,8 @@ namespace CSMWorld
|
|||
|
||||
public:
|
||||
|
||||
IdTable (CollectionBase *idCollection, Reordering reordering = Reordering_WithinTopic);
|
||||
IdTable (CollectionBase *idCollection, Reordering reordering = Reordering_None,
|
||||
Viewing viewing = Viewing_None);
|
||||
///< The ownership of \a idCollection is not transferred.
|
||||
|
||||
virtual ~IdTable();
|
||||
|
@ -63,8 +74,8 @@ namespace CSMWorld
|
|||
void addRecord (const std::string& id, UniversalId::Type type = UniversalId::Type_None);
|
||||
///< \param type Will be ignored, unless the collection supports multiple record types
|
||||
|
||||
void cloneRecord(const std::string& origin,
|
||||
const std::string& destination,
|
||||
void cloneRecord(const std::string& origin,
|
||||
const std::string& destination,
|
||||
UniversalId::Type type = UniversalId::Type_None);
|
||||
|
||||
QModelIndex getModelIndex (const std::string& id, int column) const;
|
||||
|
@ -86,6 +97,12 @@ namespace CSMWorld
|
|||
/// given in \a newOrder (baseIndex+newOrder[0] specifies the new index of row baseIndex).
|
||||
|
||||
Reordering getReordering() const;
|
||||
|
||||
Viewing getViewing() const;
|
||||
|
||||
std::pair<UniversalId, std::string> view (int row) const;
|
||||
///< Return the UniversalId and the hint for viewing \a row. If viewing is not
|
||||
/// supported by this table, return (UniversalId::Type_None, "").
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -115,10 +115,6 @@ void CSVDoc::View::setupWorldMenu()
|
|||
|
||||
world->addSeparator(); // items that don't represent single record lists follow here
|
||||
|
||||
QAction *scene = new QAction (tr ("Scene"), this);
|
||||
connect (scene, SIGNAL (triggered()), this, SLOT (addSceneSubView()));
|
||||
world->addAction (scene);
|
||||
|
||||
QAction *regionMap = new QAction (tr ("Region Map"), this);
|
||||
connect (regionMap, SIGNAL (triggered()), this, SLOT (addRegionMapSubView()));
|
||||
world->addAction (regionMap);
|
||||
|
@ -432,11 +428,6 @@ void CSVDoc::View::addFiltersSubView()
|
|||
addSubView (CSMWorld::UniversalId::Type_Filters);
|
||||
}
|
||||
|
||||
void CSVDoc::View::addSceneSubView()
|
||||
{
|
||||
addSubView (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Scene, "default"));
|
||||
}
|
||||
|
||||
void CSVDoc::View::addTopicsSubView()
|
||||
{
|
||||
addSubView (CSMWorld::UniversalId::Type_Topics);
|
||||
|
|
|
@ -168,8 +168,6 @@ namespace CSVDoc
|
|||
|
||||
void addFiltersSubView();
|
||||
|
||||
void addSceneSubView();
|
||||
|
||||
void addTopicsSubView();
|
||||
|
||||
void addJournalsSubView();
|
||||
|
|
|
@ -35,8 +35,12 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
|||
if (selectedRows.size()==1)
|
||||
{
|
||||
menu.addAction (mEditAction);
|
||||
|
||||
if (mCreateAction)
|
||||
menu.addAction(mCloneAction);
|
||||
|
||||
if (mModel->getViewing()!=CSMWorld::IdTable::Viewing_None)
|
||||
menu.addAction (mViewAction);
|
||||
}
|
||||
|
||||
if (mCreateAction)
|
||||
|
@ -230,6 +234,10 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
|||
connect (mMoveDownAction, SIGNAL (triggered()), this, SLOT (moveDownRecord()));
|
||||
addAction (mMoveDownAction);
|
||||
|
||||
mViewAction = new QAction (tr ("View"), this);
|
||||
connect (mViewAction, SIGNAL (triggered()), this, SLOT (viewRecord()));
|
||||
addAction (mViewAction);
|
||||
|
||||
connect (mProxyModel, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
||||
this, SLOT (tableSizeUpdate()));
|
||||
|
||||
|
@ -381,6 +389,23 @@ void CSVWorld::Table::moveDownRecord()
|
|||
}
|
||||
}
|
||||
|
||||
void CSVWorld::Table::viewRecord()
|
||||
{
|
||||
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
||||
|
||||
if (selectedRows.size()==1)
|
||||
{
|
||||
int row =selectedRows.begin()->row();
|
||||
|
||||
row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row();
|
||||
|
||||
std::pair<CSMWorld::UniversalId, std::string> params = mModel->view (row);
|
||||
|
||||
if (params.first.getType()!=CSMWorld::UniversalId::Type_None)
|
||||
emit editRequest (params.first, params.second);
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
||||
{
|
||||
int columns = mModel->columnCount();
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace CSVWorld
|
|||
QAction *mDeleteAction;
|
||||
QAction *mMoveUpAction;
|
||||
QAction *mMoveDownAction;
|
||||
QAction *mViewAction;
|
||||
CSMWorld::IdTableProxyModel *mProxyModel;
|
||||
CSMWorld::IdTable *mModel;
|
||||
bool mEditLock;
|
||||
|
@ -112,6 +113,8 @@ namespace CSVWorld
|
|||
|
||||
void moveDownRecord();
|
||||
|
||||
void viewRecord();
|
||||
|
||||
public slots:
|
||||
|
||||
void tableSizeUpdate();
|
||||
|
|
Loading…
Reference in a new issue