Using the typedef ModelItemValues for "QHash<int, QVariant>".
This commit is contained in:
@ -5,9 +5,9 @@
|
||||
#include "../tablemodel.h"
|
||||
|
||||
InsertRowsCommand::InsertRowsCommand(TableModel* model,
|
||||
int startRow,
|
||||
QList<QHash<int, QVariant> > valueList,
|
||||
QUndoCommand* parent)
|
||||
int startRow,
|
||||
QList<ModelItemValues> valueList,
|
||||
QUndoCommand* parent)
|
||||
: QUndoCommand(parent)
|
||||
, m_tableModel(model)
|
||||
, m_startRow(startRow)
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
|
||||
#include <QUndoCommand>
|
||||
|
||||
typedef QHash<int, QVariant> ModelItemValues;
|
||||
|
||||
class TableModel;
|
||||
|
||||
class InsertRowsCommand : public QUndoCommand {
|
||||
@ -11,9 +13,9 @@ class InsertRowsCommand : public QUndoCommand {
|
||||
/// Using simple pointer to model because there was a crash when closing the application with an
|
||||
/// unclean undo stack
|
||||
InsertRowsCommand(TableModel* model,
|
||||
int startRow,
|
||||
QList<QHash<int, QVariant> > valueList,
|
||||
QUndoCommand* parent = nullptr);
|
||||
int startRow,
|
||||
QList<ModelItemValues> valueList,
|
||||
QUndoCommand* parent = nullptr);
|
||||
|
||||
/// QUndoCommand interface
|
||||
void undo() override;
|
||||
@ -22,7 +24,7 @@ class InsertRowsCommand : public QUndoCommand {
|
||||
private:
|
||||
TableModel* m_tableModel;
|
||||
const int m_startRow;
|
||||
const QList<QHash<int, QVariant> > m_valueList;
|
||||
const QList<ModelItemValues> m_valueList;
|
||||
};
|
||||
|
||||
#endif // INSERTROWSCOMMAND_H
|
||||
|
||||
@ -20,7 +20,7 @@ RemoveRowsCommand::RemoveRowsCommand(TableModel* model,
|
||||
const int rowPosition = startRow + row;
|
||||
QModelIndex index = m_tableModel->index(rowPosition, 0);
|
||||
|
||||
QHash<int, QVariant> values = m_tableModel->getItemValues(index);
|
||||
ModelItemValues values = m_tableModel->getItemValues(index);
|
||||
|
||||
m_valueList.append(values);
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
|
||||
class TableModel;
|
||||
|
||||
typedef QHash<int, QVariant> ModelItemValues;
|
||||
|
||||
class RemoveRowsCommand : public QUndoCommand {
|
||||
public:
|
||||
// TODO don't use simple pointer to model
|
||||
@ -22,7 +24,7 @@ class RemoveRowsCommand : public QUndoCommand {
|
||||
private:
|
||||
TableModel* m_tableModel;
|
||||
const int m_startRow;
|
||||
QList<QHash<int, QVariant>> m_valueList;
|
||||
QList<ModelItemValues> m_valueList;
|
||||
};
|
||||
|
||||
#endif // REMOVEROWSCOMMAND_H
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
ModelItem::ModelItem(const QHash<int, QVariant> values)
|
||||
ModelItem::ModelItem(const ModelItemValues values)
|
||||
: m_values(values) {}
|
||||
|
||||
QVariant ModelItem::data(int role) const { return m_values.value(role); }
|
||||
|
||||
@ -3,9 +3,11 @@
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
typedef QHash<int, QVariant> ModelItemValues;
|
||||
|
||||
class ModelItem {
|
||||
public:
|
||||
ModelItem(const QHash<int, QVariant> values);
|
||||
ModelItem(const ModelItemValues values);
|
||||
|
||||
QVariant data(int role) const;
|
||||
bool setData(const QVariant& value, int role);
|
||||
|
||||
@ -120,8 +120,8 @@ bool TableModel::setItemData(const QModelIndex& index, const QMap<int, QVariant>
|
||||
return false;
|
||||
}
|
||||
|
||||
QHash<int, QVariant> TableModel::getItemValues(const QModelIndex& index) const {
|
||||
QHash<int, QVariant> values;
|
||||
ModelItemValues TableModel::getItemValues(const QModelIndex& index) const {
|
||||
ModelItemValues values;
|
||||
|
||||
QListIterator<UserRoles> i(USER_FACING_ROLES);
|
||||
while (i.hasNext()) {
|
||||
@ -169,14 +169,13 @@ void TableModel::appendItems(const QByteArray& jsonDoc) { insertItems(-1, jsonDo
|
||||
void TableModel::insertItems(int startPosition,
|
||||
const QByteArray& jsonDoc,
|
||||
const QModelIndex& parentIndex) {
|
||||
const QList<QHash<int, QVariant>> valueList =
|
||||
JsonParser::toItemValuesList(jsonDoc, ITEM_KEY_STRING);
|
||||
const QList<ModelItemValues> valueList = JsonParser::toItemValuesList(jsonDoc, ITEM_KEY_STRING);
|
||||
|
||||
insertItems(startPosition, valueList, parentIndex);
|
||||
}
|
||||
|
||||
void TableModel::insertItems(int startPosition,
|
||||
const QList<QHash<int, QVariant>>& itemValuesList,
|
||||
const QList<ModelItemValues>& itemValuesList,
|
||||
const QModelIndex& parentIndex) {
|
||||
qInfo() << "Inserting item(s) into model...";
|
||||
if (parentIndex != QModelIndex()) {
|
||||
@ -192,7 +191,7 @@ void TableModel::insertItems(int startPosition,
|
||||
m_undoStack->push(insertCommand);
|
||||
}
|
||||
|
||||
void TableModel::execInsertItems(const int firstRow, const QList<QHash<int, QVariant>> valueList) {
|
||||
void TableModel::execInsertItems(const int firstRow, const QList<ModelItemValues> valueList) {
|
||||
const int nRows = valueList.size();
|
||||
qDebug() << "Inserting" << nRows << "items...";
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@ class ModelItem;
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef QHash<int, QVariant> ModelItemValues;
|
||||
|
||||
class TableModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
@ -32,7 +34,7 @@ class TableModel : public QAbstractTableModel {
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
||||
bool setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
|
||||
|
||||
QHash<int, QVariant> getItemValues(const QModelIndex& index) const;
|
||||
ModelItemValues getItemValues(const QModelIndex& index) const;
|
||||
QJsonDocument getAllItemsAsJsonDoc() const;
|
||||
|
||||
public slots:
|
||||
@ -44,7 +46,7 @@ class TableModel : public QAbstractTableModel {
|
||||
const QByteArray& jsonDoc,
|
||||
const QModelIndex& parentIndex = QModelIndex());
|
||||
void insertItems(int startPosition,
|
||||
const QList<QHash<int, QVariant>>& itemValuesList,
|
||||
const QList<ModelItemValues>& itemValuesList,
|
||||
const QModelIndex& parentIndex = QModelIndex());
|
||||
|
||||
private:
|
||||
@ -55,7 +57,7 @@ class TableModel : public QAbstractTableModel {
|
||||
|
||||
/// *** functions ***
|
||||
/// undo/redo functions
|
||||
void execInsertItems(const int firstRow, const QList<QHash<int, QVariant>> valueList);
|
||||
void execInsertItems(const int firstRow, const QList<ModelItemValues> valueList);
|
||||
void execRemoveItems(const int firstRow, const int nRows);
|
||||
void execEditItemData(const int row, const QMap<int, QVariant>& changedValues);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user