From c96d48fb914923a75d2e979ec1852415200e38ab Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 30 Jun 2014 14:12:57 +0200 Subject: [PATCH] Nested model supports editing now. --- apps/opencs/model/world/nestedtablemodel.cpp | 11 +++++++++++ apps/opencs/model/world/nestedtablemodel.hpp | 4 ++++ apps/opencs/view/world/nestedtable.cpp | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/nestedtablemodel.cpp b/apps/opencs/model/world/nestedtablemodel.cpp index 534ec5d10..20fbd81e1 100644 --- a/apps/opencs/model/world/nestedtablemodel.cpp +++ b/apps/opencs/model/world/nestedtablemodel.cpp @@ -80,3 +80,14 @@ QVariant CSMWorld::NestedTableModel::headerData(int section, { return mMainModel->nestedHeaderData(mParentColumn, section, orientation, role); } + + +bool CSMWorld::NestedTableModel::setData ( const QModelIndex & index, const QVariant & value, int role) +{ + return mMainModel->setData(mapToSource(index), value, role); +} + +Qt::ItemFlags CSMWorld::NestedTableModel::flags(const QModelIndex& index) const +{ + return mMainModel->flags(mMainModel->index(0, mParentColumn)); +} diff --git a/apps/opencs/model/world/nestedtablemodel.hpp b/apps/opencs/model/world/nestedtablemodel.hpp index 404051efc..0af261f4d 100644 --- a/apps/opencs/model/world/nestedtablemodel.hpp +++ b/apps/opencs/model/world/nestedtablemodel.hpp @@ -45,6 +45,10 @@ namespace CSMWorld virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) const; + virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); + + virtual Qt::ItemFlags flags(const QModelIndex& index) const; + private: void setupHeaderVectors(ColumnBase::Display columnId); }; diff --git a/apps/opencs/view/world/nestedtable.cpp b/apps/opencs/view/world/nestedtable.cpp index bfadfc08c..b4bb63f3a 100644 --- a/apps/opencs/view/world/nestedtable.cpp +++ b/apps/opencs/view/world/nestedtable.cpp @@ -3,13 +3,19 @@ #include "../../model/world/universalid.hpp" #include "util.hpp" +#include + CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack, CSMWorld::NestedTableModel* model, QWidget* parent) : QTableView(parent) { - setModel(model); - setAcceptDrops(true); + + setSelectionBehavior (QAbstractItemView::SelectRows); + setSelectionMode (QAbstractItemView::ExtendedSelection); + + horizontalHeader()->setResizeMode (QHeaderView::Interactive); + verticalHeader()->hide(); int columns = model->columnCount(QModelIndex()); @@ -17,13 +23,16 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack, { CSMWorld::ColumnBase::Display display = static_cast ( model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - + CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display, undoStack, this); setItemDelegateForColumn(i, delegate); } + + setModel(model); + setAcceptDrops(true); } void CSVWorld::NestedTable::dragEnterEvent(QDragEnterEvent *event)