mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 10:09:39 +00:00
moved two helper classes from view/world/table into a separate translation unit
This commit is contained in:
parent
cc18b30e17
commit
02184526e6
4 changed files with 110 additions and 95 deletions
|
@ -13,7 +13,7 @@ set (OPENCS_SRC
|
||||||
view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp view/doc/subviewfactory.cpp
|
view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp view/doc/subviewfactory.cpp
|
||||||
view/doc/subview.cpp
|
view/doc/subview.cpp
|
||||||
|
|
||||||
view/world/table.cpp view/world/tablesubview.cpp view/world/subviews.cpp
|
view/world/table.cpp view/world/tablesubview.cpp view/world/subviews.cpp view/world/util.cpp
|
||||||
|
|
||||||
view/tools/reportsubview.cpp view/tools/subviews.cpp
|
view/tools/reportsubview.cpp view/tools/subviews.cpp
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,7 @@ set (OPENCS_HDR
|
||||||
view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp view/doc/subviewfactory.hpp
|
view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp view/doc/subviewfactory.hpp
|
||||||
view/doc/subview.hpp view/doc/subviewfactoryimp.hpp
|
view/doc/subview.hpp view/doc/subviewfactoryimp.hpp
|
||||||
|
|
||||||
view/world/table.hpp view/world/tablesubview.hpp view/world/subviews.hpp
|
view/world/table.hpp view/world/tablesubview.hpp view/world/subviews.hpp view/world/util.hpp
|
||||||
|
|
||||||
view/tools/reportsubview.hpp view/tools/subviews.hpp
|
view/tools/reportsubview.hpp view/tools/subviews.hpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
#include "table.hpp"
|
#include "table.hpp"
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QUndoStack>
|
#include <QUndoStack>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
@ -14,98 +13,7 @@
|
||||||
#include "../../model/world/idtable.hpp"
|
#include "../../model/world/idtable.hpp"
|
||||||
#include "../../model/world/record.hpp"
|
#include "../../model/world/record.hpp"
|
||||||
|
|
||||||
namespace CSVWorld
|
#include "util.hpp"
|
||||||
{
|
|
||||||
///< \brief Getting the data out of an editor widget
|
|
||||||
///
|
|
||||||
/// Really, Qt? Really?
|
|
||||||
class NastyTableModelHack : public QAbstractTableModel
|
|
||||||
{
|
|
||||||
QAbstractItemModel& mModel;
|
|
||||||
QVariant mData;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
NastyTableModelHack (QAbstractItemModel& model);
|
|
||||||
|
|
||||||
int rowCount (const QModelIndex & parent = QModelIndex()) const;
|
|
||||||
|
|
||||||
int columnCount (const QModelIndex & parent = QModelIndex()) const;
|
|
||||||
|
|
||||||
QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
|
|
||||||
|
|
||||||
bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
|
||||||
|
|
||||||
QVariant getData() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
///< \brief Use commands instead of manipulating the model directly
|
|
||||||
class CommandDelegate : public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
QUndoStack& mUndoStack;
|
|
||||||
bool mEditLock;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CommandDelegate (QUndoStack& undoStack, QObject *parent);
|
|
||||||
|
|
||||||
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
|
|
||||||
|
|
||||||
void setEditLock (bool locked);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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), mEditLock (false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
|
||||||
const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
if (!mEditLock)
|
|
||||||
{
|
|
||||||
NastyTableModelHack hack (*model);
|
|
||||||
QStyledItemDelegate::setModelData (editor, &hack, index);
|
|
||||||
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
|
||||||
}
|
|
||||||
///< \todo provide some kind of feedback to the user, indicating that editing is currently not possible.
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
|
||||||
{
|
|
||||||
mEditLock = locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
|
|
57
apps/opencs/view/world/util.cpp
Normal file
57
apps/opencs/view/world/util.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
#include <QUndoStack>
|
||||||
|
|
||||||
|
#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), mEditLock (false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void CSVWorld::CommandDelegate::setModelData (QWidget *editor, QAbstractItemModel *model,
|
||||||
|
const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
if (!mEditLock)
|
||||||
|
{
|
||||||
|
NastyTableModelHack hack (*model);
|
||||||
|
QStyledItemDelegate::setModelData (editor, &hack, index);
|
||||||
|
mUndoStack.push (new CSMWorld::ModifyCommand (*model, index, hack.getData()));
|
||||||
|
}
|
||||||
|
///< \todo provide some kind of feedback to the user, indicating that editing is currently not possible.
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::CommandDelegate::setEditLock (bool locked)
|
||||||
|
{
|
||||||
|
mEditLock = locked;
|
||||||
|
}
|
50
apps/opencs/view/world/util.hpp
Normal file
50
apps/opencs/view/world/util.hpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef CSV_WORLD_UTIL_H
|
||||||
|
#define CSV_WORLD_UTIL_H
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
class QUndoStack;
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
///< \brief Getting the data out of an editor widget
|
||||||
|
///
|
||||||
|
/// Really, Qt? Really?
|
||||||
|
class NastyTableModelHack : public QAbstractTableModel
|
||||||
|
{
|
||||||
|
QAbstractItemModel& mModel;
|
||||||
|
QVariant mData;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
NastyTableModelHack (QAbstractItemModel& model);
|
||||||
|
|
||||||
|
int rowCount (const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
|
||||||
|
int columnCount (const QModelIndex & parent = QModelIndex()) const;
|
||||||
|
|
||||||
|
QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
|
bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
|
||||||
|
QVariant getData() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
///< \brief Use commands instead of manipulating the model directly
|
||||||
|
class CommandDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
QUndoStack& mUndoStack;
|
||||||
|
bool mEditLock;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CommandDelegate (QUndoStack& undoStack, QObject *parent);
|
||||||
|
|
||||||
|
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
|
||||||
|
|
||||||
|
void setEditLock (bool locked);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue