2012-11-26 12:29:22 +01:00
|
|
|
|
|
|
|
#include "globals.hpp"
|
|
|
|
|
|
|
|
#include <QTableView>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QSortFilterProxyModel>
|
2012-11-29 16:05:28 +01:00
|
|
|
#include <QUndoStack>
|
2012-11-26 12:29:22 +01:00
|
|
|
|
|
|
|
#include "../../model/world/data.hpp"
|
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
#include "../../model/world/commands.hpp"
|
|
|
|
|
|
|
|
CSVWorld::NastyTableModelHack::NastyTableModelHack (QAbstractItemModel& model)
|
|
|
|
: mModel (model)
|
|
|
|
{}
|
|
|
|
|
|
|
|
int CSVWorld::NastyTableModelHack::rowCount (const QModelIndex & parent) const
|
|
|
|
{
|
|
|
|
return mModel.rowCount (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSVWorld::NastyTableModelHack::columnCount (const QModelIndex & parent) const
|
|
|
|
{
|
|
|
|
return mModel.columnCount (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CSVWorld::NastyTableModelHack::data (const QModelIndex & index, int role) const
|
|
|
|
{
|
|
|
|
return mModel.data (index, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSVWorld::NastyTableModelHack::setData ( const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
mData = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CSVWorld::NastyTableModelHack::getData() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSVWorld::CommandDelegate::CommandDelegate (QUndoStack& undoStack, QObject *parent)
|
|
|
|
: QStyledItemDelegate (parent), mUndoStack (undoStack)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
|
|
|
const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
NastyTableModelHack hack (*model);
|
|
|
|
QStyledItemDelegate::setModelData (editor, &hack, index);
|
|
|
|
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
CSVWorld::Globals::Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack)
|
2012-11-26 12:29:22 +01:00
|
|
|
: SubView (id)
|
|
|
|
{
|
|
|
|
QTableView *table = new QTableView();
|
|
|
|
|
|
|
|
setWidget (table);
|
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
QAbstractTableModel *model = data.getTableModel (id);
|
|
|
|
|
|
|
|
int columns = model->columnCount();
|
|
|
|
|
|
|
|
for (int i=1; i<columns; ++i)
|
|
|
|
{
|
|
|
|
CommandDelegate *delegate = new CommandDelegate (undoStack, table);
|
|
|
|
table->setItemDelegateForColumn (i, delegate);
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:29:22 +01:00
|
|
|
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
|
2012-11-29 16:05:28 +01:00
|
|
|
proxyModel->setSourceModel (model);
|
2012-11-26 12:29:22 +01:00
|
|
|
|
|
|
|
table->setModel (proxyModel);
|
|
|
|
table->horizontalHeader()->setResizeMode (QHeaderView::Interactive);
|
|
|
|
table->verticalHeader()->hide();
|
|
|
|
table->setSortingEnabled (true);
|
2012-11-27 10:42:46 +01:00
|
|
|
table->setSelectionBehavior (QAbstractItemView::SelectRows);
|
|
|
|
table->setSelectionMode (QAbstractItemView::ExtendedSelection);
|
2012-11-26 12:29:22 +01:00
|
|
|
|
|
|
|
/// \todo make initial layout fill the whole width of the table
|
|
|
|
}
|