dotherside/lib/include/DOtherSide/DosQAbstractItemModel.h

178 lines
6.3 KiB
C
Raw Normal View History

#pragma once
// Qt
#include <QAbstractItemModel>
#include <QAbstractListModel>
#include <QAbstractTableModel>
// DOtherSide
#include "DOtherSide/DOtherSideTypes.h"
#include "DOtherSide/DosIQAbstractItemModelImpl.h"
2016-01-23 18:40:17 +01:00
#include "DOtherSide/OnSlotExecutedHandler.h"
2016-02-27 15:07:23 +01:00
namespace DOS {
2017-03-22 21:21:57 +01:00
template<class T>
class DosQAbstractGenericModel : public T, public DosIQAbstractItemModelImpl
{
public:
/// Constructor
2017-03-22 21:21:57 +01:00
DosQAbstractGenericModel(void *modelObject,
DosIQMetaObjectPtr metaObject,
OnSlotExecuted onSlotExecuted,
DosQAbstractItemModelCallbacks callbacks);
/// @see IDynamicQObject::emitSignal
2016-03-28 21:36:34 +02:00
bool emitSignal(QObject *emitter, const QString &name, const std::vector<QVariant> &argumentsValues) override;
2017-03-05 19:30:57 +01:00
/// @see QAbstractItemModel::metaObject()
const QMetaObject *metaObject() const override;
2017-03-05 19:30:57 +01:00
/// @see QAbstractItemModel::qt_metacall
int qt_metacall(QMetaObject::Call, int, void **) override;
/// Return the model's row count
2016-02-27 15:07:23 +01:00
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/// Return the model's column count
2016-02-27 15:07:23 +01:00
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
/// Return the QVariant at the given index
2016-02-27 15:07:23 +01:00
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
/// Sets the QVariant value at the given index and role
2016-02-27 15:07:23 +01:00
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
/// Return the item flags for the given index
2016-02-27 15:07:23 +01:00
Qt::ItemFlags flags(const QModelIndex &index) const override;
/// Return the data for the given role and section in the header with the specified orientation
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
2017-03-05 19:06:07 +01:00
/// Return the index associated at the given row and column
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
2017-03-05 19:06:07 +01:00
/// Return the parent for the given child index
QModelIndex parent(const QModelIndex &child) const override;
/// Return the dModelPointer
2016-02-27 15:07:23 +01:00
void *modelObject();
/// Return the roleNames
QHash<int, QByteArray> roleNames() const override;
/// Expose beginInsertRows
void publicBeginInsertRows(const QModelIndex &index, int first, int last) override;
/// Expose endInsertRows
void publicEndInsertRows() override;
/// Expose beginRemoveRows
void publicBeginRemoveRows(const QModelIndex &index, int first, int last) override;
/// Expose endInsertRows
void publicEndRemoveRows() override;
2017-03-05 19:06:07 +01:00
/// Expose beginInsertColumns
void publicBeginInsertColumns(const QModelIndex &index, int first, int last) override;
/// Expose endInsertColumns
void publicEndInsertColumns() override;
/// Expose beginRemoveColumns
void publicBeginRemoveColumns(const QModelIndex &index, int first, int last) override;
/// Expose endInsertColumns
void publicEndRemoveColumns() override;
/// Expose beginResetModel
void publicBeginResetModel() override;
/// Expose endResetModel
void publicEndResetModel() override;
/// Expose dataChanged
2016-02-27 15:07:23 +01:00
void publicDataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles = QVector<int>()) override;
2017-03-05 19:06:07 +01:00
/// Expose createIndex
QModelIndex publicCreateIndex(int row, int column, void *data = nullptr) const override;
/// Expose the not overriden flags
2017-03-22 22:23:17 +01:00
Qt::ItemFlags defaultFlags(const QModelIndex &index) const override;
/// Expose the not overriden header data
2017-03-22 22:23:17 +01:00
QVariant defaultHeaderData(int section, Qt::Orientation orientation, int role) const override;
/// Expose the not overriden roleNames
2017-03-22 22:23:17 +01:00
QHash<int, QByteArray> defaultRoleNames() const override;
/// Expose the not overriden setData
bool defaultSetData(const QModelIndex &index, const QVariant &value, int role) override;
/// Expose the hasChildren
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
/// Expose hasIndex
bool hasIndex(int row, int column, const QModelIndex &parent) const;
/// Expose the canFetchMore
bool canFetchMore(const QModelIndex &parent) const override;
/// Expose the not override canFetchMore
bool defaultCanFetchMore(const QModelIndex &parent) const override;
/// Expose the fetchMore
2017-04-09 14:34:47 +02:00
void fetchMore(const QModelIndex &parent) override;
/// Expose the not overriden fetchMore
void defaultFetchMore(const QModelIndex &parent) override;
private:
2016-01-23 18:40:17 +01:00
std::unique_ptr<DosIQObjectImpl> m_impl;
2016-02-27 15:07:23 +01:00
void *m_modelObject;
DosQAbstractItemModelCallbacks m_callbacks;
};
class DosQAbstractItemModel : public DosQAbstractGenericModel<QAbstractItemModel>
{
public:
DosQAbstractItemModel(void *modelObject,
DosIQMetaObjectPtr metaObject,
OnSlotExecuted onSlotExecuted,
DosQAbstractItemModelCallbacks callbacks);
2017-04-09 12:31:51 +02:00
using DosQAbstractGenericModel::DosQAbstractGenericModel;
bool defaultHasChildren(const QModelIndex &parent) const override;
};
class DosQAbstractTableModel : public DosQAbstractGenericModel<QAbstractTableModel>
{
public:
DosQAbstractTableModel(void *modelObject,
DosIQMetaObjectPtr metaObject,
OnSlotExecuted onSlotExecuted,
DosQAbstractItemModelCallbacks callbacks);
2017-04-09 14:34:47 +02:00
QModelIndex defaultParent(const QModelIndex &child) const;
QModelIndex defaultIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
bool defaultHasChildren(const QModelIndex &parent) const override;
};
class DosQAbstractListModel : public DosQAbstractGenericModel<QAbstractListModel>
{
public:
DosQAbstractListModel(void *modelObject,
DosIQMetaObjectPtr metaObject,
OnSlotExecuted onSlotExecuted,
DosQAbstractItemModelCallbacks callbacks);
2017-04-09 14:34:47 +02:00
QModelIndex defaultParent(const QModelIndex &child) const;
QModelIndex defaultIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
int defaultColumnCount(const QModelIndex &parent) const;
bool defaultHasChildren(const QModelIndex &parent) const override;
};
2017-03-22 21:21:57 +01:00
} // namespace DOS