Nested table sits inside it's own layout now.

This commit is contained in:
Marek Kochanowicz 2014-06-17 18:28:49 +02:00
parent 5bee682bb3
commit ce5e889015
4 changed files with 88 additions and 63 deletions

View file

@ -1,4 +1,3 @@
#include "idtable.hpp"
#include <QDebug>
@ -17,8 +16,7 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const
{
if (hasChildren(parent))
{
int nestedRows = mIdCollection->getNestedRowsCount(parent.row(), parent.column());
return nestedRows;
return mIdCollection->getNestedRowsCount(parent.row(), parent.column());
}
return mIdCollection->getSize();
@ -26,7 +24,8 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const
int CSMWorld::IdTable::columnCount (const QModelIndex & parent) const
{
if (parent.isValid())
if (parent.isValid() &&
parent.data().isValid())
{
return mIdCollection->getNestedColumnsCount(parent.row(), parent.column());
}
@ -42,16 +41,21 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const
if (role==Qt::EditRole && !mIdCollection->getColumn (index.column()).isEditable())
return QVariant();
if (hasChildren(index))
if (index.internalId() != 0)
{
std::pair<int, int> parentAdress(unfoldIndexAdress(index.internalId()));
return mIdCollection->getNestedData(parentAdress.first, parentAdress.second, index.row(), index.column());
return mIdCollection->getNestedData(parentAdress.first,
parentAdress.second,
index.row(),
index.column());
} else {
return mIdCollection->getData (index.row(), index.column());
}
}
QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation, int role) const
QVariant CSMWorld::IdTable::headerData (int section,
Qt::Orientation orientation,
int role) const
{
if (orientation==Qt::Vertical)
return QVariant();
@ -291,10 +295,7 @@ std::pair< int, int > CSMWorld::IdTable::unfoldIndexAdress (unsigned int id) con
bool CSMWorld::IdTable::hasChildren(const QModelIndex& index) const
{
return (index.isValid() &&
CSMWorld::ColumnBase::Display_Nested == static_cast<CSMWorld::ColumnBase::Display> (headerData
(index.column(),
Qt::Horizontal,
CSMWorld::ColumnBase::Role_Display).toInt()) &&
CSMWorld::ColumnBase::Display_Nested == static_cast<CSMWorld::ColumnBase::Display> (headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()) &&
index.internalId() == 0 &&
index.data().isValid());
}

View file

@ -601,8 +601,7 @@ int CSMWorld::RefIdCollection::getNestedRowsCount(int row, int column) const
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdaptor (localIndex.second));
const int count = adaptor.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
return count;
return adaptor.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
}
int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const

View file

@ -20,6 +20,7 @@
#include <QPushButton>
#include <QToolButton>
#include <QTableView>
#include <QDebug>
#include "../../model/world/columnbase.hpp"
#include "../../model/world/idtable.hpp"
@ -366,9 +367,12 @@ void CSVWorld::EditWidget::remake(int row)
QVBoxLayout *mainLayout = new QVBoxLayout(mMainWidget);
QGridLayout *unlockedLayout = new QGridLayout();
QGridLayout *lockedLayout = new QGridLayout();
QVBoxLayout *tablesLayout = new QVBoxLayout();
mainLayout->addLayout(lockedLayout, 0);
mainLayout->addWidget(line, 1);
mainLayout->addLayout(unlockedLayout, 2);
mainLayout->addLayout(tablesLayout, 3);
mainLayout->addStretch(1);
int unlocked = 0;
@ -384,15 +388,12 @@ void CSVWorld::EditWidget::remake(int row)
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
if (display == CSMWorld::ColumnBase::Display_Nested)
if (mTable->hasChildren(mTable->index(row, i)))
{
const QModelIndex& parent = mTable->index(row, i);
if (parent.data().isValid() && mTable->hasChildren(parent))
{
QTableView* table = new QTableView(this);
QTableView* table = new QTableView();
table->setModel(mTable);
table->setRootIndex(mTable->index(row, i));
}
tablesLayout->addWidget(table);
} else
{
mDispatcher.makeDelegate (display);

View file

@ -38,16 +38,23 @@ namespace CSVWorld
{
const CSMWorld::IdTable* mTable;
public:
NotEditableSubDelegate(const CSMWorld::IdTable* table, QObject * parent = 0);
NotEditableSubDelegate(const CSMWorld::IdTable* table,
QObject * parent = 0);
virtual void setEditorData (QLabel* editor, const QModelIndex& index) const;
virtual void setEditorData (QLabel* editor,
const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display) const;
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paint (QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual QSize sizeHint (const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QWidget *createEditor (QWidget *parent,
@ -75,16 +82,20 @@ namespace CSVWorld
std::auto_ptr<refWrapper> mIndexWrapper;
public:
DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);
DialogueDelegateDispatcherProxy(QWidget* editor,
CSMWorld::ColumnBase::Display display);
QWidget* getEditor() const;
public slots:
void editorDataCommited();
void setIndex(const QModelIndex& index);
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>& data, const CSMDoc::Document* document);
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>& data,
const CSMDoc::Document* document);
signals:
void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
void editorDataCommited(QWidget* editor,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display);
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
const CSMWorld::UniversalId& id,
@ -105,30 +116,42 @@ namespace CSVWorld
NotEditableSubDelegate mNotEditableDelegate;
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
std::vector<DialogueDelegateDispatcherProxy*> mProxys;
//once we move to the C++11 we should use unique_ptr
public:
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack);
DialogueDelegateDispatcher(QObject* parent,
CSMWorld::IdTable* table,
QUndoStack& undoStack);
~DialogueDelegateDispatcher();
CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display);
QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index);
QWidget* makeEditor(CSMWorld::ColumnBase::Display display,
const QModelIndex& index);
///< will return null if delegate is not present, parent of the widget is same as for dispatcher itself
virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
virtual void setEditorData (QWidget* editor,
const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const;
virtual void setModelData (QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display) const;
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paint (QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual QSize sizeHint (const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
private slots:
void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
void editorDataCommited(QWidget* editor, const QModelIndex& index,
CSMWorld::ColumnBase::Display display);
signals:
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
@ -149,7 +172,8 @@ namespace CSVWorld
public:
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table, QUndoStack& undoStack, bool createAndDelete = false);
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
QUndoStack& undoStack, bool createAndDelete = false);
void remake(int row);