Commit 5f5351b1 authored by André Hoarau's avatar André Hoarau 🍆

add recordmodel

parent 5f33f770
#include "recordmodel.h"
#include <QDebug>
#include <QSqlRecord>
#include <QSqlError>
#include <QSqlQuery>
RecordModel::RecordModel(QObject *parent, const QString &tableName)
: SortFilterProxyModel(parent, tableName)
{
sort(0);
}
// bool RecordModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
//{
// int leftCrop = sourceRowValue(left.row(), left.parent(), "planting_id").toInt();
// int rightCrop = sourceRowValue(right.row(), right.parent(), "planting_id").toInt();
// return leftCrop < rightCrop;
//}
bool RecordModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QDate date = sourceFieldDate(sourceRow, sourceParent, "date");
bool isInYear = QDate(m_year, 1, 1) <= date && date <= QDate(m_year, 12, 31);
return isInYear && SortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
#ifndef RECORDMODEL_H
#define RECORDMODEL_H
#include <QDate>
#include "core_global.h"
#include "sortfilterproxymodel.h"
class CORESHARED_EXPORT RecordModel : public SortFilterProxyModel
{
Q_OBJECT
// Q_PROPERTY(int plantingId READ plantingId WRITE setPlantingId NOTIFY plantingIdChanged)
public:
RecordModel(QObject *parent = nullptr, const QString &tableName = "record_view");
// bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
// int plantingId() const;
// void setPlantingId(int plantingId);
// signals:
// void plantingIdChanged();
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
// private:
// int m_plantingId { -1 };
};
#endif // RECORDMODEL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment