8#include "ModelSource.h"
10#include <QMetaProperty>
12#include "charts_datasource_logging.h"
14ModelSource::ModelSource(
QObject *parent)
17 connect(
this, &ModelSource::modelChanged,
this, &ModelSource::dataChanged);
18 connect(
this, &ModelSource::columnChanged,
this, &ModelSource::dataChanged);
19 connect(
this, &ModelSource::roleChanged,
this, &ModelSource::dataChanged);
20 connect(
this, &ModelSource::indexColumnsChanged,
this, &ModelSource::dataChanged);
23int ModelSource::role()
const
29 if (m_role < 0 && !m_roleName.
isEmpty()) {
36QString ModelSource::roleName()
const
41int ModelSource::column()
const
51bool ModelSource::indexColumns()
const
53 return m_indexColumns;
56int ModelSource::itemCount()
const
65QVariant ModelSource::item(
int index)
const
81 qCWarning(DATASOURCE) <<
"ModelSource: Invalid role " << m_role << m_roleName;
86 if (!m_indexColumns && (m_column < 0 || m_column > m_model->
columnCount())) {
87 qCDebug(DATASOURCE) <<
"ModelSource: Invalid column" << m_column;
91 auto modelIndex = m_indexColumns ? m_model->
index(0, index) : m_model->
index(index, m_column);
92 if (modelIndex.isValid()) {
93 return m_model->
data(modelIndex, m_role);
101 if (!m_model || itemCount() <= 0) {
109 auto minProperty = m_model->
property(
"minimum");
110 auto maxProperty = m_model->
property(
"maximum");
111 if (minProperty.isValid() && minProperty != maxProperty) {
115 QVariant result = std::numeric_limits<float>::max();
116 for (
int i = 0; i < itemCount(); ++i) {
117 result = std::min(result, item(i), variantCompare);
122QVariant ModelSource::maximum()
const
124 if (!m_model || itemCount() <= 0) {
132 auto minProperty = m_model->
property(
"minimum");
133 auto maxProperty = m_model->
property(
"maximum");
134 if (maxProperty.isValid() && maxProperty != minProperty) {
138 QVariant result = std::numeric_limits<float>::min();
139 for (
int i = 0; i < itemCount(); ++i) {
140 result = std::max(result, item(i), variantCompare);
145void ModelSource::setRole(
int role)
147 if (role == m_role) {
159void ModelSource::setRoleName(
const QString &name)
161 if (name == m_roleName) {
173void ModelSource::setColumn(
int column)
175 if (column == m_column) {
183void ModelSource::setIndexColumns(
bool index)
185 if (index == m_indexColumns) {
189 m_indexColumns = index;
190 Q_EMIT indexColumnsChanged();
195 if (m_model == model) {
221 if (minimumIndex != -1) {
223 if (minimum.hasNotifySignal()) {
225 connect(m_model, minimum.notifySignal(),
this, slot);
226 m_minimum = minimum.read(m_model);
231 if (maximumIndex != -1) {
233 if (maximum.hasNotifySignal()) {
235 connect(m_model, maximum.notifySignal(),
this, slot);
236 m_maximum = maximum.read(m_model);
244void ModelSource::onMinimumChanged()
246 auto newMinimum = m_model->
property(
"minimum");
247 if (newMinimum.isValid() && newMinimum != m_minimum) {
248 m_minimum = newMinimum;
252void ModelSource::onMaximumChanged()
254 auto newMaximum = m_model->
property(
"maximum");
255 if (newMaximum.isValid() && newMaximum != m_maximum) {
256 m_maximum = newMaximum;
260#include "moc_ModelSource.cpp"
Abstract base class for data sources.
QString name(GameStandardAction id)
virtual int columnCount(const QModelIndex &parent) const const=0
virtual QVariant data(const QModelIndex &index, int role) const const=0
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
virtual QHash< int, QByteArray > roleNames() const const
virtual int rowCount(const QModelIndex &parent) const const=0
void rowsInserted(const QModelIndex &parent, int first, int last)
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
void rowsRemoved(const QModelIndex &parent, int first, int last)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
QVariant property(const char *name) const const
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
QByteArray toLatin1() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const