/
friendlyperch
/
QGrid
Обзор
Документация
Войти
/
friendlyperch
/
QGrid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev-ver1
src/models/UniversalTableModel.h
83 строки
3 KB
okuntsev
change add and remove logic
14 янв 2026, 18:27
14 янв 2026, 18:27
97097c2
Код
Авторство
О чём код?
#pragma once #include <functional> #include <QAbstractTableModel> #include <QMetaProperty> #include <QMetaMethod> #include <QSet> #include "QGrid/ActiveListBase.h" #include "QGrid/GridColumn.h" #include "QGrid/GridCommon.h" class UniversalTableModel : public QAbstractTableModel { Q_OBJECT public: UniversalTableModel(QObject *parent = nullptr); int rowCount(const QModelIndex &index) const; int columnCount(const QModelIndex &index) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; Qt::ItemFlags flags(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); Mode getMode() const; void setMode(const Mode &value); QVector<GridColumn *> getColumns() const; void setColumns(const QVector<GridColumn *> &value); ActiveListBase *getDatasource() const; void setDatasource(ActiveListBase *value); GridColumn *getColumn(int index) const; QObject *getObjectByIndex(int index); void setCheckableSelectionEnabled(bool enabled); bool getCheckableSelectionEnabled() const; void setRowSelected(int row, bool selected); bool isRowSelected(int row) const; QSet<int> getSelectedRows() const; void setSelectionChangedCallback(std::function<void(int, bool)> callback); protected: QMetaMethod findOnObjectPropertyChangedMethod(); QString getPropertyName(QObject *sender, int senderSignalIndex); private: void subscribeToAllObject(ActiveListBase *value); void subscribeToObjectProperties(QObject *obj); void unsubscribeFromObjectProperties(QObject *obj); void unsubscribeFromAllObjects(ActiveListBase *value); int getColumnIndexByVisualIndex(int visualIndex) const; signals: void datasourceChanged(); public slots: void setFilters(QMap<QString, QVariant> value); void reloadDatasource(); protected slots: void onDatasourceCountChanged(); void onDatasourceInsert(size_t index, size_t count); void onDatasourceRemove(size_t index, size_t count); void onObjectPropertyChanged(); private: QString table; QVector<GridColumn *> columns; QMap<QString, QVariant> filters; Mode mode; GridColumn *idColumn = nullptr; ActiveListBase *datasource = nullptr; QMetaMethod onObjectPropertyChangedMethod; bool mCheckableSelectionEnabled = false; QSet<int> mSelectedRows; std::function<void(int, bool)> mSelectionChangedCallback; };