1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-13 23:09:40 +00:00

added option to add or remove rows

This commit is contained in:
Marek Kochanowicz 2014-07-01 20:52:27 +02:00
parent 172f1a1301
commit fcd082c6a5
5 changed files with 74 additions and 3 deletions

View file

@ -151,7 +151,7 @@ namespace CSMWorld
public: public:
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent); DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
virtual void redo(); virtual void redo();
@ -170,7 +170,7 @@ namespace CSMWorld
public: public:
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent); AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
virtual void redo(); virtual void redo();

View file

@ -91,3 +91,18 @@ Qt::ItemFlags CSMWorld::NestedTableModel::flags(const QModelIndex& index) const
{ {
return mMainModel->flags(mMainModel->index(0, mParentColumn)); return mMainModel->flags(mMainModel->index(0, mParentColumn));
} }
std::string CSMWorld::NestedTableModel::getParentId() const
{
return mId;
}
int CSMWorld::NestedTableModel::getParentColumn() const
{
return mParentColumn;
}
CSMWorld::IdTable* CSMWorld::NestedTableModel::model() const
{
return mMainModel;
}

View file

@ -31,6 +31,12 @@ namespace CSMWorld
IdTable* parentModel); IdTable* parentModel);
//parent is the parent of columns to work with. Columnid provides information about the column //parent is the parent of columns to work with. Columnid provides information about the column
std::string getParentId() const;
int getParentColumn() const;
CSMWorld::IdTable* model() const;
virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const; virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const; virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const;

View file

@ -1,16 +1,19 @@
#include "nestedtable.hpp" #include "nestedtable.hpp"
#include "../../model/world/nestedtablemodel.hpp" #include "../../model/world/nestedtablemodel.hpp"
#include "../../model/world/universalid.hpp" #include "../../model/world/universalid.hpp"
#include "../../model/world/commands.hpp"
#include "util.hpp" #include "util.hpp"
#include <QHeaderView> #include <QHeaderView>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QMenu>
CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack, CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack,
CSMWorld::NestedTableModel* model, CSMWorld::NestedTableModel* model,
QWidget* parent) QWidget* parent)
: QTableView(parent), : QTableView(parent),
mUndoStack(undoStack) mUndoStack(undoStack),
mModel(model)
{ {
setSelectionBehavior (QAbstractItemView::SelectRows); setSelectionBehavior (QAbstractItemView::SelectRows);
@ -34,7 +37,16 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack,
} }
setModel(model); setModel(model);
setAcceptDrops(true); setAcceptDrops(true);
mAddNewRowAction = new QAction (tr ("Add new row"), this);
connect(mAddNewRowAction, SIGNAL(triggered()),
this, SLOT(addNewRowActionTriggered()));
mRemoveRowAction = new QAction (tr ("Remove row"), this);
connect(mRemoveRowAction, SIGNAL(triggered()),
this, SLOT(removeRowActionTriggered()));
} }
void CSVWorld::NestedTable::dragEnterEvent(QDragEnterEvent *event) void CSVWorld::NestedTable::dragEnterEvent(QDragEnterEvent *event)
@ -48,4 +60,31 @@ void CSVWorld::NestedTable::dragMoveEvent(QDragMoveEvent *event)
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event) void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
{ {
QModelIndexList selectedRows = selectionModel()->selectedRows(); QModelIndexList selectedRows = selectionModel()->selectedRows();
QMenu menu(this);
if (selectionModel()->selectedRows().size() == 1)
menu.addAction(mRemoveRowAction);
menu.addAction(mAddNewRowAction);
menu.exec (event->globalPos());
}
void CSVWorld::NestedTable::removeRowActionTriggered()
{
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().begin()->row(),
mModel->getParentColumn()));
}
void CSVWorld::NestedTable::addNewRowActionTriggered()
{
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().size(),
mModel->getParentColumn()));
} }

View file

@ -28,6 +28,7 @@ namespace CSVWorld
QAction *mAddNewRowAction; QAction *mAddNewRowAction;
QAction *mRemoveRowAction; QAction *mRemoveRowAction;
QUndoStack& mUndoStack; QUndoStack& mUndoStack;
CSMWorld::NestedTableModel* mModel;
public: public:
NestedTable(QUndoStack& undoStack, NestedTable(QUndoStack& undoStack,
@ -41,6 +42,16 @@ namespace CSVWorld
private: private:
void contextMenuEvent (QContextMenuEvent *event); void contextMenuEvent (QContextMenuEvent *event);
private slots:
void removeRowActionTriggered();
void addNewRowActionTriggered();
signals:
void addNewRow();
void removeRow(int row);
}; };
} }