mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:15:32 +00:00
added set/unset region actions to region map
This commit is contained in:
parent
fc4195a88f
commit
1892550833
2 changed files with 76 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/columns.hpp"
|
||||
|
||||
void CSVWorld::RegionMap::contextMenuEvent (QContextMenuEvent *event)
|
||||
{
|
||||
|
@ -46,6 +47,17 @@ void CSVWorld::RegionMap::contextMenuEvent (QContextMenuEvent *event)
|
|||
menu.addAction (mCreateCellsAction);
|
||||
}
|
||||
|
||||
if (getSelectedCells().size()>0)
|
||||
{
|
||||
if (!mRegionId.empty())
|
||||
{
|
||||
mSetRegionAction->setText (QString::fromUtf8 (("Set region to " + mRegionId).c_str()));
|
||||
menu.addAction (mSetRegionAction);
|
||||
}
|
||||
|
||||
menu.addAction (mUnsetRegionAction);
|
||||
}
|
||||
|
||||
menu.exec (event->globalPos());
|
||||
}
|
||||
|
||||
|
@ -131,6 +143,36 @@ QModelIndexList CSVWorld::RegionMap::getMissingRegionCells() const
|
|||
return list;
|
||||
}
|
||||
|
||||
void CSVWorld::RegionMap::setRegion (const std::string& regionId)
|
||||
{
|
||||
QModelIndexList selected = getSelectedCells();
|
||||
|
||||
QAbstractItemModel *regionModel = model();
|
||||
|
||||
CSMWorld::IdTable *cellsModel = &dynamic_cast<CSMWorld::IdTable&> (*
|
||||
mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
|
||||
|
||||
QString regionId2 = QString::fromUtf8 (regionId.c_str());
|
||||
|
||||
if (selected.size()>1)
|
||||
mDocument.getUndoStack().beginMacro (tr ("Set Region"));
|
||||
|
||||
for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
|
||||
{
|
||||
std::string cellId = regionModel->data (*iter, CSMWorld::RegionMap::Role_CellId).
|
||||
toString().toUtf8().constData();
|
||||
|
||||
QModelIndex index = cellsModel->getModelIndex (cellId,
|
||||
cellsModel->findColumnIndex (CSMWorld::Columns::ColumnId_Region));
|
||||
|
||||
mDocument.getUndoStack().push (
|
||||
new CSMWorld::ModifyCommand (*cellsModel, index, regionId2));
|
||||
}
|
||||
|
||||
if (selected.size()>1)
|
||||
mDocument.getUndoStack().endMacro();
|
||||
}
|
||||
|
||||
CSVWorld::RegionMap::RegionMap (const CSMWorld::UniversalId& universalId,
|
||||
CSMDoc::Document& document, QWidget *parent)
|
||||
: QTableView (parent), mEditLock (false), mDocument (document)
|
||||
|
@ -160,6 +202,14 @@ CSVWorld::RegionMap::RegionMap (const CSMWorld::UniversalId& universalId,
|
|||
mCreateCellsAction = new QAction (tr ("Create Cells Action"), this);
|
||||
connect (mCreateCellsAction, SIGNAL (triggered()), this, SLOT (createCells()));
|
||||
addAction (mCreateCellsAction);
|
||||
|
||||
mSetRegionAction = new QAction (tr ("Set Region"), this);
|
||||
connect (mSetRegionAction, SIGNAL (triggered()), this, SLOT (setRegion()));
|
||||
addAction (mSetRegionAction);
|
||||
|
||||
mUnsetRegionAction = new QAction (tr ("Unset Region"), this);
|
||||
connect (mUnsetRegionAction, SIGNAL (triggered()), this, SLOT (unsetRegion()));
|
||||
addAction (mUnsetRegionAction);
|
||||
}
|
||||
|
||||
void CSVWorld::RegionMap::setEditLock (bool locked)
|
||||
|
@ -213,4 +263,20 @@ void CSVWorld::RegionMap::createCells()
|
|||
|
||||
if (selected.size()>1)
|
||||
mDocument.getUndoStack().endMacro();
|
||||
}
|
||||
|
||||
void CSVWorld::RegionMap::setRegion()
|
||||
{
|
||||
if (mEditLock)
|
||||
return;
|
||||
|
||||
setRegion (mRegionId);
|
||||
}
|
||||
|
||||
void CSVWorld::RegionMap::unsetRegion()
|
||||
{
|
||||
if (mEditLock)
|
||||
return;
|
||||
|
||||
setRegion ("");
|
||||
}
|
|
@ -25,8 +25,11 @@ namespace CSVWorld
|
|||
QAction *mClearSelectionAction;
|
||||
QAction *mSelectRegionsAction;
|
||||
QAction *mCreateCellsAction;
|
||||
QAction *mSetRegionAction;
|
||||
QAction *mUnsetRegionAction;
|
||||
bool mEditLock;
|
||||
CSMDoc::Document& mDocument;
|
||||
std::string mRegionId;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -42,6 +45,9 @@ namespace CSVWorld
|
|||
QModelIndexList getMissingRegionCells() const;
|
||||
///< Unselected cells within all regions that have at least one selected cell.
|
||||
|
||||
void setRegion (const std::string& regionId);
|
||||
///< Set region Id of selected cells.
|
||||
|
||||
public:
|
||||
|
||||
RegionMap (const CSMWorld::UniversalId& universalId, CSMDoc::Document& document,
|
||||
|
@ -58,6 +64,10 @@ namespace CSVWorld
|
|||
void selectRegions();
|
||||
|
||||
void createCells();
|
||||
|
||||
void setRegion();
|
||||
|
||||
void unsetRegion();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue