mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Actually using new nestedmodel
This commit is contained in:
parent
1fb18873cb
commit
b63f2f4cd5
4 changed files with 81 additions and 9 deletions
|
@ -1,10 +1,11 @@
|
||||||
#include "nestedtablemodel.hpp"
|
#include "nestedtablemodel.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include "./idtable.hpp"
|
#include "./idtable.hpp"
|
||||||
|
|
||||||
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
|
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
|
||||||
ColumnBase::Display columnId,
|
ColumnBase::Display columnId,
|
||||||
CSMWorld::IdTable* parentModel)
|
CSMWorld::IdTable* parentModel)
|
||||||
: mParentColumn(parent.column())
|
: mParentColumn(parent.column())
|
||||||
{
|
{
|
||||||
const int parentRow = parent.row();
|
const int parentRow = parent.row();
|
||||||
|
@ -20,7 +21,7 @@ QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceI
|
||||||
{
|
{
|
||||||
return createIndex(sourceIndex.row(), sourceIndex.column());
|
return createIndex(sourceIndex.row(), sourceIndex.column());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
@ -32,3 +33,46 @@ QModelIndex CSMWorld::NestedTableModel::mapToSource(const QModelIndex& proxyInde
|
||||||
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
|
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
|
||||||
return sourceModel()->index(proxyIndex.row(), proxyIndex.column(), parent);
|
return sourceModel()->index(proxyIndex.row(), proxyIndex.column(), parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSMWorld::NestedTableModel::rowCount(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
assert (!index.isValid());
|
||||||
|
|
||||||
|
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
|
||||||
|
|
||||||
|
return table->rowCount(table->getModelIndex(mId, mParentColumn));
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSMWorld::NestedTableModel::columnCount(const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
assert (!parent.isValid());
|
||||||
|
|
||||||
|
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
|
||||||
|
|
||||||
|
return table->columnCount(table->getModelIndex(mId, mParentColumn));
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelIndex& parent) const
|
||||||
|
{
|
||||||
|
assert (!parent.isValid());
|
||||||
|
|
||||||
|
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
|
||||||
|
|
||||||
|
unsigned rows = table->rowCount(parent);
|
||||||
|
usigned columns = table->columnCount(parent);
|
||||||
|
|
||||||
|
if (row < 0 ||
|
||||||
|
row >= rows ||
|
||||||
|
column < 0 ||
|
||||||
|
column >= columns)
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createIndex(row, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex CSMWorld::NestedTableModel::parent(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#ifndef CSM_WOLRD_NESTEDTABLEMODEL_H
|
#ifndef CSM_WOLRD_NESTEDTABLEMODEL_H
|
||||||
#define CSM_WOLRD_NESTEDTABLEMODEL_H
|
#define CSM_WOLRD_NESTEDTABLEMODEL_H
|
||||||
|
|
||||||
|
@ -26,16 +25,24 @@ namespace CSMWorld
|
||||||
std::string mId;
|
std::string mId;
|
||||||
std::vector<std::string> mHeaderTitle;
|
std::vector<std::string> mHeaderTitle;
|
||||||
std::vector<ColumnBase::Display> mHeaderDisplay;
|
std::vector<ColumnBase::Display> mHeaderDisplay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NestedTableModel(const QModelIndex& parent,
|
NestedTableModel(const QModelIndex& parent,
|
||||||
ColumnBase::Display displayType,
|
ColumnBase::Display displayType,
|
||||||
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
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
virtual int rowCount(const QModelIndex& parent) const;
|
||||||
|
|
||||||
|
virtual int columnCount(const QModelIndex& parent) const;
|
||||||
|
|
||||||
|
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
||||||
|
|
||||||
|
virtual QModelIndex parent(const QModelIndex& index) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "../../model/world/nestedtablemodel.hpp"
|
||||||
#include "../../model/world/columnbase.hpp"
|
#include "../../model/world/columnbase.hpp"
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
#include "../../model/world/columns.hpp"
|
#include "../../model/world/columns.hpp"
|
||||||
|
@ -324,6 +325,14 @@ CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher()
|
||||||
=============================================================EditWidget=====================================================
|
=============================================================EditWidget=====================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
CSVWorld::EditWidget::~EditWidget()
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < mNestedModels.size(); ++i)
|
||||||
|
{
|
||||||
|
delete mNestedModels[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSVWorld::EditWidget::EditWidget(QWidget *parent, int row, CSMWorld::IdTable* table, QUndoStack& undoStack, bool createAndDelete) :
|
CSVWorld::EditWidget::EditWidget(QWidget *parent, int row, CSMWorld::IdTable* table, QUndoStack& undoStack, bool createAndDelete) :
|
||||||
mDispatcher(this, table, undoStack),
|
mDispatcher(this, table, undoStack),
|
||||||
QScrollArea(parent),
|
QScrollArea(parent),
|
||||||
|
@ -340,6 +349,11 @@ mTable(table)
|
||||||
|
|
||||||
void CSVWorld::EditWidget::remake(int row)
|
void CSVWorld::EditWidget::remake(int row)
|
||||||
{
|
{
|
||||||
|
for (unsigned i = 0; i < mNestedModels.size(); ++i)
|
||||||
|
{
|
||||||
|
delete mNestedModels[i];
|
||||||
|
}
|
||||||
|
|
||||||
if (mMainWidget)
|
if (mMainWidget)
|
||||||
{
|
{
|
||||||
delete mMainWidget;
|
delete mMainWidget;
|
||||||
|
@ -379,7 +393,7 @@ void CSVWorld::EditWidget::remake(int row)
|
||||||
int locked = 0;
|
int locked = 0;
|
||||||
const int columns = mTable->columnCount();
|
const int columns = mTable->columnCount();
|
||||||
|
|
||||||
for (int i=0; i<columns; ++i)
|
for (unsigned i=0; i<columns; ++i)
|
||||||
{
|
{
|
||||||
int flags = mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt();
|
int flags = mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt();
|
||||||
|
|
||||||
|
@ -390,9 +404,12 @@ void CSVWorld::EditWidget::remake(int row)
|
||||||
|
|
||||||
if (mTable->hasChildren(mTable->index(row, i)))
|
if (mTable->hasChildren(mTable->index(row, i)))
|
||||||
{
|
{
|
||||||
|
mNestedModels.push_back(new CSMWorld::NestedTableModel (mTable->index(row, i), display, mTable));
|
||||||
|
|
||||||
QTableView* table = new QTableView();
|
QTableView* table = new QTableView();
|
||||||
table->setModel(mTable);
|
|
||||||
table->setRootIndex(mTable->index(row, i));
|
table->setModel(*(mNestedModels.rbegin()));
|
||||||
|
|
||||||
tablesLayout->addWidget(table);
|
tablesLayout->addWidget(table);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ class QVBoxLayout;
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class IdTable;
|
class IdTable;
|
||||||
|
class NestedTableModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
|
@ -169,12 +170,15 @@ namespace CSVWorld
|
||||||
QWidget* mMainWidget;
|
QWidget* mMainWidget;
|
||||||
CSMWorld::IdTable* mTable;
|
CSMWorld::IdTable* mTable;
|
||||||
QUndoStack& mUndoStack;
|
QUndoStack& mUndoStack;
|
||||||
|
std::vector<CSMWorld::NestedTableModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
|
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
|
||||||
QUndoStack& undoStack, bool createAndDelete = false);
|
QUndoStack& undoStack, bool createAndDelete = false);
|
||||||
|
|
||||||
|
~EditWidget();
|
||||||
|
|
||||||
void remake(int row);
|
void remake(int row);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in a new issue