mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-13 21:39:41 +00:00
Nested table sits inside it's own layout now.
This commit is contained in:
parent
5bee682bb3
commit
ce5e889015
4 changed files with 88 additions and 63 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -17,8 +16,7 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const
|
||||||
{
|
{
|
||||||
if (hasChildren(parent))
|
if (hasChildren(parent))
|
||||||
{
|
{
|
||||||
int nestedRows = mIdCollection->getNestedRowsCount(parent.row(), parent.column());
|
return mIdCollection->getNestedRowsCount(parent.row(), parent.column());
|
||||||
return nestedRows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mIdCollection->getSize();
|
return mIdCollection->getSize();
|
||||||
|
@ -26,7 +24,8 @@ int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const
|
||||||
|
|
||||||
int CSMWorld::IdTable::columnCount (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());
|
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())
|
if (role==Qt::EditRole && !mIdCollection->getColumn (index.column()).isEditable())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (hasChildren(index))
|
if (index.internalId() != 0)
|
||||||
{
|
{
|
||||||
std::pair<int, int> parentAdress(unfoldIndexAdress(index.internalId()));
|
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 {
|
} else {
|
||||||
return mIdCollection->getData (index.row(), index.column());
|
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)
|
if (orientation==Qt::Vertical)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -68,7 +72,7 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role)
|
bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole)
|
if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole)
|
||||||
{
|
{
|
||||||
|
@ -291,10 +295,7 @@ std::pair< int, int > CSMWorld::IdTable::unfoldIndexAdress (unsigned int id) con
|
||||||
bool CSMWorld::IdTable::hasChildren(const QModelIndex& index) const
|
bool CSMWorld::IdTable::hasChildren(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
return (index.isValid() &&
|
return (index.isValid() &&
|
||||||
CSMWorld::ColumnBase::Display_Nested == static_cast<CSMWorld::ColumnBase::Display> (headerData
|
CSMWorld::ColumnBase::Display_Nested == static_cast<CSMWorld::ColumnBase::Display> (headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()) &&
|
||||||
(index.column(),
|
|
||||||
Qt::Horizontal,
|
|
||||||
CSMWorld::ColumnBase::Role_Display).toInt()) &&
|
|
||||||
index.internalId() == 0 &&
|
index.internalId() == 0 &&
|
||||||
index.data().isValid());
|
index.data().isValid());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdaptor (localIndex.second));
|
||||||
|
|
||||||
const int count = adaptor.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
|
return adaptor.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
|
int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../../model/world/columnbase.hpp"
|
#include "../../model/world/columnbase.hpp"
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
|
@ -133,25 +134,25 @@ void CSVWorld::DialogueDelegateDispatcherProxy::tableMimeDataDropped(const std::
|
||||||
if (mDisplay == CSMWorld::ColumnBase::Display_Referenceable)
|
if (mDisplay == CSMWorld::ColumnBase::Display_Referenceable)
|
||||||
{
|
{
|
||||||
if ( type == CSMWorld::UniversalId::Type_Activator
|
if ( type == CSMWorld::UniversalId::Type_Activator
|
||||||
|| type == CSMWorld::UniversalId::Type_Potion
|
|| type == CSMWorld::UniversalId::Type_Potion
|
||||||
|| type == CSMWorld::UniversalId::Type_Apparatus
|
|| type == CSMWorld::UniversalId::Type_Apparatus
|
||||||
|| type == CSMWorld::UniversalId::Type_Armor
|
|| type == CSMWorld::UniversalId::Type_Armor
|
||||||
|| type == CSMWorld::UniversalId::Type_Book
|
|| type == CSMWorld::UniversalId::Type_Book
|
||||||
|| type == CSMWorld::UniversalId::Type_Clothing
|
|| type == CSMWorld::UniversalId::Type_Clothing
|
||||||
|| type == CSMWorld::UniversalId::Type_Container
|
|| type == CSMWorld::UniversalId::Type_Container
|
||||||
|| type == CSMWorld::UniversalId::Type_Creature
|
|| type == CSMWorld::UniversalId::Type_Creature
|
||||||
|| type == CSMWorld::UniversalId::Type_Door
|
|| type == CSMWorld::UniversalId::Type_Door
|
||||||
|| type == CSMWorld::UniversalId::Type_Ingredient
|
|| type == CSMWorld::UniversalId::Type_Ingredient
|
||||||
|| type == CSMWorld::UniversalId::Type_CreatureLevelledList
|
|| type == CSMWorld::UniversalId::Type_CreatureLevelledList
|
||||||
|| type == CSMWorld::UniversalId::Type_ItemLevelledList
|
|| type == CSMWorld::UniversalId::Type_ItemLevelledList
|
||||||
|| type == CSMWorld::UniversalId::Type_Light
|
|| type == CSMWorld::UniversalId::Type_Light
|
||||||
|| type == CSMWorld::UniversalId::Type_Lockpick
|
|| type == CSMWorld::UniversalId::Type_Lockpick
|
||||||
|| type == CSMWorld::UniversalId::Type_Miscellaneous
|
|| type == CSMWorld::UniversalId::Type_Miscellaneous
|
||||||
|| type == CSMWorld::UniversalId::Type_Npc
|
|| type == CSMWorld::UniversalId::Type_Npc
|
||||||
|| type == CSMWorld::UniversalId::Type_Probe
|
|| type == CSMWorld::UniversalId::Type_Probe
|
||||||
|| type == CSMWorld::UniversalId::Type_Repair
|
|| type == CSMWorld::UniversalId::Type_Repair
|
||||||
|| type == CSMWorld::UniversalId::Type_Static
|
|| type == CSMWorld::UniversalId::Type_Static
|
||||||
|| type == CSMWorld::UniversalId::Type_Weapon)
|
|| type == CSMWorld::UniversalId::Type_Weapon)
|
||||||
{
|
{
|
||||||
type = CSMWorld::UniversalId::Type_Referenceable;
|
type = CSMWorld::UniversalId::Type_Referenceable;
|
||||||
}
|
}
|
||||||
|
@ -304,7 +305,7 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
|
||||||
} //lisp cond pairs would be nice in the C++
|
} //lisp cond pairs would be nice in the C++
|
||||||
|
|
||||||
connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)),
|
connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)),
|
||||||
this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
|
this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
|
||||||
|
|
||||||
mProxys.push_back(proxy); //deleted in the destructor
|
mProxys.push_back(proxy); //deleted in the destructor
|
||||||
}
|
}
|
||||||
|
@ -334,7 +335,7 @@ mTable(table)
|
||||||
remake (row);
|
remake (row);
|
||||||
|
|
||||||
connect(&mDispatcher, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
|
connect(&mDispatcher, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
|
||||||
this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
|
this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::EditWidget::remake(int row)
|
void CSVWorld::EditWidget::remake(int row)
|
||||||
|
@ -366,9 +367,12 @@ void CSVWorld::EditWidget::remake(int row)
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout(mMainWidget);
|
QVBoxLayout *mainLayout = new QVBoxLayout(mMainWidget);
|
||||||
QGridLayout *unlockedLayout = new QGridLayout();
|
QGridLayout *unlockedLayout = new QGridLayout();
|
||||||
QGridLayout *lockedLayout = new QGridLayout();
|
QGridLayout *lockedLayout = new QGridLayout();
|
||||||
|
QVBoxLayout *tablesLayout = new QVBoxLayout();
|
||||||
|
|
||||||
mainLayout->addLayout(lockedLayout, 0);
|
mainLayout->addLayout(lockedLayout, 0);
|
||||||
mainLayout->addWidget(line, 1);
|
mainLayout->addWidget(line, 1);
|
||||||
mainLayout->addLayout(unlockedLayout, 2);
|
mainLayout->addLayout(unlockedLayout, 2);
|
||||||
|
mainLayout->addLayout(tablesLayout, 3);
|
||||||
mainLayout->addStretch(1);
|
mainLayout->addStretch(1);
|
||||||
|
|
||||||
int unlocked = 0;
|
int unlocked = 0;
|
||||||
|
@ -384,15 +388,12 @@ void CSVWorld::EditWidget::remake(int row)
|
||||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
||||||
(mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
(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);
|
QTableView* table = new QTableView();
|
||||||
if (parent.data().isValid() && mTable->hasChildren(parent))
|
table->setModel(mTable);
|
||||||
{
|
table->setRootIndex(mTable->index(row, i));
|
||||||
QTableView* table = new QTableView(this);
|
tablesLayout->addWidget(table);
|
||||||
table->setModel(mTable);
|
|
||||||
table->setRootIndex(mTable->index(row, i));
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
mDispatcher.makeDelegate (display);
|
mDispatcher.makeDelegate (display);
|
||||||
|
|
|
@ -38,16 +38,23 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
const CSMWorld::IdTable* mTable;
|
const CSMWorld::IdTable* mTable;
|
||||||
public:
|
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
|
///< does nothing
|
||||||
|
|
||||||
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
virtual QSize sizeHint (const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const;
|
||||||
///< does nothing
|
///< does nothing
|
||||||
|
|
||||||
virtual QWidget *createEditor (QWidget *parent,
|
virtual QWidget *createEditor (QWidget *parent,
|
||||||
|
@ -75,16 +82,20 @@ namespace CSVWorld
|
||||||
std::auto_ptr<refWrapper> mIndexWrapper;
|
std::auto_ptr<refWrapper> mIndexWrapper;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);
|
DialogueDelegateDispatcherProxy(QWidget* editor,
|
||||||
|
CSMWorld::ColumnBase::Display display);
|
||||||
QWidget* getEditor() const;
|
QWidget* getEditor() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void editorDataCommited();
|
void editorDataCommited();
|
||||||
void setIndex(const QModelIndex& index);
|
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:
|
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,
|
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
|
||||||
const CSMWorld::UniversalId& id,
|
const CSMWorld::UniversalId& id,
|
||||||
|
@ -105,30 +116,42 @@ namespace CSVWorld
|
||||||
|
|
||||||
NotEditableSubDelegate mNotEditableDelegate;
|
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:
|
public:
|
||||||
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack);
|
DialogueDelegateDispatcher(QObject* parent,
|
||||||
|
CSMWorld::IdTable* table,
|
||||||
|
QUndoStack& undoStack);
|
||||||
|
|
||||||
~DialogueDelegateDispatcher();
|
~DialogueDelegateDispatcher();
|
||||||
|
|
||||||
CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display);
|
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
|
///< 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
|
///< does nothing
|
||||||
|
|
||||||
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
virtual QSize sizeHint (const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const;
|
||||||
///< does nothing
|
///< does nothing
|
||||||
|
|
||||||
private slots:
|
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:
|
signals:
|
||||||
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
|
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
|
||||||
|
@ -149,7 +172,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
public:
|
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);
|
void remake(int row);
|
||||||
|
|
||||||
|
@ -167,7 +191,7 @@ namespace CSVWorld
|
||||||
QVBoxLayout* mMainLayout;
|
QVBoxLayout* mMainLayout;
|
||||||
CSMWorld::IdTable* mTable;
|
CSMWorld::IdTable* mTable;
|
||||||
QUndoStack& mUndoStack;
|
QUndoStack& mUndoStack;
|
||||||
std::string mCurrentId;
|
std::string mCurrentId;
|
||||||
bool mLocked;
|
bool mLocked;
|
||||||
const CSMDoc::Document& mDocument;
|
const CSMDoc::Document& mDocument;
|
||||||
TableBottomBox* mBottom;
|
TableBottomBox* mBottom;
|
||||||
|
@ -181,9 +205,9 @@ namespace CSVWorld
|
||||||
bool sorting = false);
|
bool sorting = false);
|
||||||
|
|
||||||
virtual void setEditLock (bool locked);
|
virtual void setEditLock (bool locked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void changeCurrentId(const std::string& newCurrent);
|
void changeCurrentId(const std::string& newCurrent);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue