forked from mirror/openmw-tes3mp
added context menu with selection functions to region map
This commit is contained in:
parent
d205d5f0af
commit
0516d95253
7 changed files with 214 additions and 18 deletions
|
@ -60,7 +60,7 @@ opencs_hdrs_noqt (view/doc
|
||||||
opencs_units (view/world
|
opencs_units (view/world
|
||||||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||||
cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool
|
cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool
|
||||||
scenetoolmode infocreator scriptedit dialoguesubview previewsubview
|
scenetoolmode infocreator scriptedit dialoguesubview previewsubview regionmap
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (view/render
|
opencs_units (view/render
|
||||||
|
|
|
@ -406,6 +406,17 @@ QVariant CSMWorld::RegionMap::data (const QModelIndex& index, int role) const
|
||||||
return QString::fromUtf8 (stream.str().c_str());
|
return QString::fromUtf8 (stream.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role==Role_Region)
|
||||||
|
{
|
||||||
|
CellIndex cellIndex = getIndex (index);
|
||||||
|
|
||||||
|
std::map<CellIndex, CellDescription>::const_iterator cell =
|
||||||
|
mMap.find (cellIndex);
|
||||||
|
|
||||||
|
if (cell!=mMap.end() && !cell->second.mRegion.empty())
|
||||||
|
return QString::fromUtf8 (Misc::StringUtils::lowerCase (cell->second.mRegion).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,11 @@ namespace CSMWorld
|
||||||
|
|
||||||
typedef std::pair<int, int> CellIndex;
|
typedef std::pair<int, int> CellIndex;
|
||||||
|
|
||||||
|
enum Role
|
||||||
|
{
|
||||||
|
Role_Region = Qt::UserRole
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct CellDescription
|
struct CellDescription
|
||||||
|
|
142
apps/opencs/view/world/regionmap.cpp
Normal file
142
apps/opencs/view/world/regionmap.cpp
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
|
||||||
|
#include "regionmap.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QContextMenuEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
#include "../../model/world/regionmap.hpp"
|
||||||
|
|
||||||
|
void CSVWorld::RegionMap::contextMenuEvent (QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
QMenu menu (this);
|
||||||
|
|
||||||
|
if (getUnselectedCells().size()>0)
|
||||||
|
menu.addAction (mSelectAllAction);
|
||||||
|
|
||||||
|
if (selectionModel()->selectedIndexes().size()>0)
|
||||||
|
menu.addAction (mClearSelectionAction);
|
||||||
|
|
||||||
|
if (getMissingRegionCells().size()>0)
|
||||||
|
menu.addAction (mSelectRegionsAction);
|
||||||
|
|
||||||
|
menu.exec (event->globalPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndexList CSVWorld::RegionMap::getUnselectedCells() const
|
||||||
|
{
|
||||||
|
const QAbstractItemModel *model = QTableView::model();
|
||||||
|
|
||||||
|
int rows = model->rowCount();
|
||||||
|
int columns = model->columnCount();
|
||||||
|
|
||||||
|
QModelIndexList selected = selectionModel()->selectedIndexes();
|
||||||
|
std::sort (selected.begin(), selected.end());
|
||||||
|
|
||||||
|
QModelIndexList all;
|
||||||
|
|
||||||
|
for (int y=0; y<rows; ++y)
|
||||||
|
for (int x=0; x<columns; ++x)
|
||||||
|
{
|
||||||
|
QModelIndex index = model->index (y, x);
|
||||||
|
if (model->data (index, Qt::BackgroundRole)!=QBrush (Qt::DiagCrossPattern))
|
||||||
|
all.push_back (index);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort (all.begin(), all.end());
|
||||||
|
|
||||||
|
QModelIndexList list;
|
||||||
|
|
||||||
|
std::set_difference (all.begin(), all.end(), selected.begin(), selected.end(),
|
||||||
|
std::back_inserter (list));
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndexList CSVWorld::RegionMap::getMissingRegionCells() const
|
||||||
|
{
|
||||||
|
const QAbstractItemModel *model = QTableView::model();
|
||||||
|
|
||||||
|
QModelIndexList selected = selectionModel()->selectedIndexes();
|
||||||
|
|
||||||
|
std::set<std::string> regions;
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (selected.begin()); iter!=selected.end(); ++iter)
|
||||||
|
{
|
||||||
|
std::string region =
|
||||||
|
model->data (*iter, CSMWorld::RegionMap::Role_Region).toString().toUtf8().constData();
|
||||||
|
|
||||||
|
if (!region.empty())
|
||||||
|
regions.insert (region);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndexList list;
|
||||||
|
|
||||||
|
QModelIndexList unselected = getUnselectedCells();
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (unselected.begin()); iter!=unselected.end(); ++iter)
|
||||||
|
{
|
||||||
|
std::string region =
|
||||||
|
model->data (*iter, CSMWorld::RegionMap::Role_Region).toString().toUtf8().constData();
|
||||||
|
|
||||||
|
if (!region.empty() && regions.find (region)!=regions.end())
|
||||||
|
list.push_back (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::RegionMap::RegionMap (QAbstractItemModel *model, QWidget *parent)
|
||||||
|
: QTableView (parent)
|
||||||
|
{
|
||||||
|
verticalHeader()->hide();
|
||||||
|
horizontalHeader()->hide();
|
||||||
|
|
||||||
|
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||||
|
|
||||||
|
setModel (model);
|
||||||
|
|
||||||
|
resizeColumnsToContents();
|
||||||
|
resizeRowsToContents();
|
||||||
|
|
||||||
|
mSelectAllAction = new QAction (tr ("Select All"), this);
|
||||||
|
connect (mSelectAllAction, SIGNAL (triggered()), this, SLOT (selectAll()));
|
||||||
|
addAction (mSelectAllAction);
|
||||||
|
|
||||||
|
mClearSelectionAction = new QAction (tr ("Clear Selection"), this);
|
||||||
|
connect (mClearSelectionAction, SIGNAL (triggered()), this, SLOT (clearSelection()));
|
||||||
|
addAction (mClearSelectionAction);
|
||||||
|
|
||||||
|
mSelectRegionsAction = new QAction (tr ("Select Regions"), this);
|
||||||
|
connect (mSelectRegionsAction, SIGNAL (triggered()), this, SLOT (selectRegions()));
|
||||||
|
addAction (mSelectRegionsAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::RegionMap::setEditLock (bool locked)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::RegionMap::selectAll()
|
||||||
|
{
|
||||||
|
QModelIndexList unselected = getUnselectedCells();
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (unselected.begin()); iter!=unselected.end(); ++iter)
|
||||||
|
selectionModel()->select (*iter, QItemSelectionModel::Select);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::RegionMap::clearSelection()
|
||||||
|
{
|
||||||
|
selectionModel()->clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::RegionMap::selectRegions()
|
||||||
|
{
|
||||||
|
QModelIndexList unselected = getMissingRegionCells();
|
||||||
|
|
||||||
|
for (QModelIndexList::const_iterator iter (unselected.begin()); iter!=unselected.end(); ++iter)
|
||||||
|
selectionModel()->select (*iter, QItemSelectionModel::Select);
|
||||||
|
}
|
45
apps/opencs/view/world/regionmap.hpp
Normal file
45
apps/opencs/view/world/regionmap.hpp
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef CSV_WORLD_REGIONMAP_H
|
||||||
|
#define CSV_WORLD_REGIONMAP_H
|
||||||
|
|
||||||
|
#include <QTableView>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
class QAbstractItemModel;
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
class RegionMap : public QTableView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QAction *mSelectAllAction;
|
||||||
|
QAction *mClearSelectionAction;
|
||||||
|
QAction *mSelectRegionsAction;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void contextMenuEvent (QContextMenuEvent *event);
|
||||||
|
|
||||||
|
QModelIndexList getUnselectedCells() const;
|
||||||
|
///< Note non-existent cells are not listed.
|
||||||
|
|
||||||
|
QModelIndexList getMissingRegionCells() const;
|
||||||
|
///< Unselected cells within all regions that have at least one selected cell.
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RegionMap (QAbstractItemModel *model, QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setEditLock (bool locked);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void selectAll();
|
||||||
|
|
||||||
|
void clearSelection();
|
||||||
|
|
||||||
|
void selectRegions();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,29 +1,18 @@
|
||||||
|
|
||||||
#include "regionmapsubview.hpp"
|
#include "regionmapsubview.hpp"
|
||||||
|
|
||||||
#include <QTableView>
|
#include "regionmap.hpp"
|
||||||
#include <QHeaderView>
|
|
||||||
|
|
||||||
CSVWorld::RegionMapSubView::RegionMapSubView (CSMWorld::UniversalId universalId,
|
CSVWorld::RegionMapSubView::RegionMapSubView (CSMWorld::UniversalId universalId,
|
||||||
CSMDoc::Document& document)
|
CSMDoc::Document& document)
|
||||||
: CSVDoc::SubView (universalId)
|
: CSVDoc::SubView (universalId)
|
||||||
{
|
{
|
||||||
mTable = new QTableView (this);
|
mRegionMap = new RegionMap (document.getData().getTableModel (universalId), this);
|
||||||
|
|
||||||
mTable->verticalHeader()->hide();
|
setWidget (mRegionMap);
|
||||||
mTable->horizontalHeader()->hide();
|
|
||||||
|
|
||||||
mTable->setSelectionMode (QAbstractItemView::ExtendedSelection);
|
|
||||||
|
|
||||||
mTable->setModel (document.getData().getTableModel (universalId));
|
|
||||||
|
|
||||||
mTable->resizeColumnsToContents();
|
|
||||||
mTable->resizeRowsToContents();
|
|
||||||
|
|
||||||
setWidget (mTable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::RegionMapSubView::setEditLock (bool locked)
|
void CSVWorld::RegionMapSubView::setEditLock (bool locked)
|
||||||
{
|
{
|
||||||
|
mRegionMap->setEditLock (locked);
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "../doc/subview.hpp"
|
#include "../doc/subview.hpp"
|
||||||
|
|
||||||
class QTableView;
|
class QAction;
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
|
@ -12,9 +12,13 @@ namespace CSMDoc
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
|
class RegionMap;
|
||||||
|
|
||||||
class RegionMapSubView : public CSVDoc::SubView
|
class RegionMapSubView : public CSVDoc::SubView
|
||||||
{
|
{
|
||||||
QTableView *mTable;
|
Q_OBJECT
|
||||||
|
|
||||||
|
RegionMap *mRegionMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue