2019-11-17 23:09:11 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2019 Filippo Cucchetto.
|
|
|
|
Contact: https://github.com/filcuc/dotherside
|
|
|
|
|
|
|
|
This file is part of the DOtherSide library.
|
|
|
|
|
|
|
|
The DOtherSide library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version.
|
|
|
|
|
|
|
|
The DOtherSide library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the DOtherSide library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Qt
|
2018-03-29 23:25:33 +02:00
|
|
|
#include <QtCore/QAbstractItemModel>
|
|
|
|
#include <QtCore/QAbstractListModel>
|
|
|
|
#include <QtCore/QAbstractTableModel>
|
2017-03-25 15:08:04 +01:00
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
// DOtherSide
|
|
|
|
#include "DOtherSide/DOtherSideTypes.h"
|
2018-10-07 17:31:33 +02:00
|
|
|
#include "DOtherSide/DosQMetaObject.h"
|
2017-03-05 18:18:30 +01:00
|
|
|
#include "DOtherSide/DosIQAbstractItemModelImpl.h"
|
2016-01-04 23:03:57 +01:00
|
|
|
|
2016-02-27 15:07:23 +01:00
|
|
|
namespace DOS {
|
2016-01-04 23:03:57 +01:00
|
|
|
|
2017-03-22 21:21:57 +01:00
|
|
|
template<class T>
|
|
|
|
class DosQAbstractGenericModel : public T, public DosIQAbstractItemModelImpl
|
2016-01-04 23:03:57 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Constructor
|
2017-03-22 21:21:57 +01:00
|
|
|
DosQAbstractGenericModel(void *modelObject,
|
|
|
|
DosIQMetaObjectPtr metaObject,
|
2018-10-07 17:31:33 +02:00
|
|
|
DObjectCallback dObjectCallback,
|
2017-04-02 14:47:42 +02:00
|
|
|
DosQAbstractItemModelCallbacks callbacks);
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// @see IDynamicQObject::emitSignal
|
2016-03-28 21:36:34 +02:00
|
|
|
bool emitSignal(QObject *emitter, const QString &name, const std::vector<QVariant> &argumentsValues) override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
2017-03-05 19:30:57 +01:00
|
|
|
/// @see QAbstractItemModel::metaObject()
|
2016-01-16 20:19:48 +01:00
|
|
|
const QMetaObject *metaObject() const override;
|
|
|
|
|
2017-03-05 19:30:57 +01:00
|
|
|
/// @see QAbstractItemModel::qt_metacall
|
2016-01-16 20:19:48 +01:00
|
|
|
int qt_metacall(QMetaObject::Call, int, void **) override;
|
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// Return the model's row count
|
2016-02-27 15:07:23 +01:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2016-01-08 19:31:33 +01:00
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// Return the model's column count
|
2016-02-27 15:07:23 +01:00
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
2016-01-08 19:31:33 +01:00
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// 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;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// 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;
|
2016-01-08 19:31:33 +01:00
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// Return the item flags for the given index
|
2016-02-27 15:07:23 +01:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2016-01-08 19:31:33 +01:00
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// 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;
|
2016-01-08 19:31:33 +01:00
|
|
|
|
2017-03-05 19:06:07 +01:00
|
|
|
/// Return the index associated at the given row and column
|
2017-03-05 18:34:35 +01:00
|
|
|
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
|
2017-03-05 18:34:35 +01:00
|
|
|
QModelIndex parent(const QModelIndex &child) const override;
|
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// Return the dModelPointer
|
2016-02-27 15:07:23 +01:00
|
|
|
void *modelObject();
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Return the roleNames
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
/// Expose beginInsertRows
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicBeginInsertRows(const QModelIndex &index, int first, int last) override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Expose endInsertRows
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicEndInsertRows() override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Expose beginRemoveRows
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicBeginRemoveRows(const QModelIndex &index, int first, int last) override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Expose endInsertRows
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicEndRemoveRows() override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
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;
|
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
/// Expose beginResetModel
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicBeginResetModel() override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Expose endResetModel
|
2016-03-03 22:38:52 +01:00
|
|
|
void publicEndResetModel() override;
|
2016-01-04 23:03:57 +01:00
|
|
|
|
|
|
|
/// Expose dataChanged
|
2016-02-27 15:07:23 +01:00
|
|
|
void publicDataChanged(const QModelIndex &topLeft,
|
|
|
|
const QModelIndex &bottomRight,
|
2016-03-03 22:38:52 +01:00
|
|
|
const QVector<int> &roles = QVector<int>()) override;
|
2017-03-05 18:34:35 +01:00
|
|
|
|
2017-03-05 19:06:07 +01:00
|
|
|
/// Expose createIndex
|
|
|
|
QModelIndex publicCreateIndex(int row, int column, void *data = nullptr) const override;
|
|
|
|
|
2017-03-25 15:08:04 +01:00
|
|
|
/// Expose the not overriden flags
|
2017-03-22 22:23:17 +01:00
|
|
|
Qt::ItemFlags defaultFlags(const QModelIndex &index) const override;
|
2017-03-25 15:08:04 +01:00
|
|
|
|
|
|
|
/// 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;
|
2017-03-25 15:08:04 +01:00
|
|
|
|
|
|
|
/// Expose the not overriden roleNames
|
2017-03-22 22:23:17 +01:00
|
|
|
QHash<int, QByteArray> defaultRoleNames() const override;
|
|
|
|
|
2017-03-25 15:08:04 +01:00
|
|
|
/// Expose the not overriden setData
|
|
|
|
bool defaultSetData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
|
2017-04-02 16:12:18 +02:00
|
|
|
/// Expose the hasChildren
|
|
|
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
2017-04-17 00:52:43 +04:00
|
|
|
/// Expose hasIndex
|
2018-10-07 10:42:59 +02:00
|
|
|
bool hasIndex(int row, int column, const QModelIndex &parent) const override;
|
2017-04-17 00:52:43 +04:00
|
|
|
|
2017-04-02 16:12:18 +02:00
|
|
|
/// 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;
|
2017-04-02 16:12:18 +02:00
|
|
|
|
|
|
|
/// Expose the not overriden fetchMore
|
|
|
|
void defaultFetchMore(const QModelIndex &parent) override;
|
|
|
|
|
2016-01-04 23:03:57 +01:00
|
|
|
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;
|
2017-04-02 14:47:42 +02:00
|
|
|
DosQAbstractItemModelCallbacks m_callbacks;
|
2016-01-04 23:03:57 +01:00
|
|
|
};
|
|
|
|
|
2017-03-25 15:08:04 +01:00
|
|
|
class DosQAbstractItemModel : public DosQAbstractGenericModel<QAbstractItemModel>
|
|
|
|
{
|
|
|
|
public:
|
2017-04-09 12:31:51 +02:00
|
|
|
using DosQAbstractGenericModel::DosQAbstractGenericModel;
|
2018-10-07 16:49:07 +02:00
|
|
|
|
2017-04-02 16:12:18 +02:00
|
|
|
bool defaultHasChildren(const QModelIndex &parent) const override;
|
2017-03-25 15:08:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DosQAbstractTableModel : public DosQAbstractGenericModel<QAbstractTableModel>
|
|
|
|
{
|
|
|
|
public:
|
2018-10-07 16:47:53 +02:00
|
|
|
using DosQAbstractGenericModel::DosQAbstractGenericModel;
|
2017-03-25 15:08:04 +01:00
|
|
|
|
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;
|
2017-04-02 16:12:18 +02:00
|
|
|
bool defaultHasChildren(const QModelIndex &parent) const override;
|
2017-03-25 15:08:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DosQAbstractListModel : public DosQAbstractGenericModel<QAbstractListModel>
|
|
|
|
{
|
|
|
|
public:
|
2018-10-07 16:47:53 +02:00
|
|
|
using DosQAbstractGenericModel::DosQAbstractGenericModel;
|
2017-03-25 15:08:04 +01:00
|
|
|
|
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;
|
2017-03-25 15:08:04 +01:00
|
|
|
int defaultColumnCount(const QModelIndex &parent) const;
|
2017-04-02 16:12:18 +02:00
|
|
|
bool defaultHasChildren(const QModelIndex &parent) const override;
|
2017-03-25 15:08:04 +01:00
|
|
|
};
|
2017-03-22 21:21:57 +01:00
|
|
|
|
2016-01-07 12:04:40 +01:00
|
|
|
} // namespace DOS
|