Skip to content

Commit

Permalink
Filter button for Sudauswahl
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgeoisLab committed Sep 8, 2024
1 parent 1ab3b38 commit 86756a5
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 377 deletions.
2 changes: 1 addition & 1 deletion kleiner-brauhelfer-core/kleiner-brauhelfer-core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VER_MAJ = 2
# Datenbankversion
VER_MIN = 9
# Patchversion
VER_PAT = 4
VER_PAT = 5

VERSION = $$sprintf("%1.%2.%3", $$VER_MAJ, $$VER_MIN, $$VER_PAT)
DEFINES += VER_MAJ=\"$$VER_MAJ\" VER_MIN=\"$$VER_MIN\" VER_PAT=\"$$VER_PAT\"
Expand Down
17 changes: 17 additions & 0 deletions kleiner-brauhelfer-core/modelkategorien.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ ModelKategorien::ModelKategorien(Brauhelfer *bh, const QSqlDatabase &db) :
SqlTableModel(bh, db),
bh(bh)
{
connect(this, &QAbstractItemModel::modelReset, this, &ModelKategorien::addEmpty);
}

void ModelKategorien::addEmpty()
{
for (int r = 0; r < rowCount(); ++r)
if (data(r, ColName).toString().isEmpty())
return;
append({{ColName, ""}});
}

bool ModelKategorien::setDataExt(const QModelIndex &idx, const QVariant &value)
Expand Down Expand Up @@ -39,3 +48,11 @@ void ModelKategorien::defaultValues(QMap<int, QVariant> &values) const
{
values[ColName] = getUniqueName(index(0, ColName), values[ColName], true);
}

bool ModelKategorien::removeRows(int row, int count, const QModelIndex &parent)
{
for (int r = row; r < row + count; ++r)
if (data(r, ColName).toString().isEmpty())
return false;
return SqlTableModel::removeRows(row, count, parent);
}
7 changes: 6 additions & 1 deletion kleiner-brauhelfer-core/modelkategorien.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Brauhelfer;

class ModelKategorien : public SqlTableModel
class LIB_EXPORT ModelKategorien : public SqlTableModel
{
Q_OBJECT

Expand All @@ -29,6 +29,11 @@ class ModelKategorien : public SqlTableModel
ModelKategorien(Brauhelfer* bh, const QSqlDatabase &db = QSqlDatabase());
bool setDataExt(const QModelIndex &idx, const QVariant &value) Q_DECL_OVERRIDE;
void defaultValues(QMap<int, QVariant> &values) const Q_DECL_OVERRIDE;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;

private:

void addEmpty();

private:

Expand Down
45 changes: 44 additions & 1 deletion kleiner-brauhelfer-core/proxymodelsud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ProxyModelSud::ProxyModelSud(QObject *parent) :
mFilterStatus(Alle),
mMinDate(QDateTime()),
mMaxDate(QDateTime()),
mFilterText(QString())
mFilterText(QString()),
mFilterKategorie(QString())
{
}

Expand Down Expand Up @@ -97,6 +98,20 @@ void ProxyModelSud::setFilterText(const QString& text)
}
}

QString ProxyModelSud::filterKategorie() const
{
return mFilterKategorie;
}

void ProxyModelSud::setFilterKategorie(const QString& kategorie)
{
if (mFilterKategorie != kategorie)
{
mFilterKategorie = kategorie;
invalidateRowsFilter();
}
}

bool ProxyModelSud::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
QModelIndex idx;
Expand Down Expand Up @@ -136,6 +151,12 @@ bool ProxyModelSud::filterAcceptsRow(int source_row, const QModelIndex &source_p
if (idx.isValid())
accept = dateInRange(sourceModel()->data(idx).toDateTime());
}
if (accept && !mFilterKategorie.isEmpty())
{
idx = sourceModel()->index(source_row, ModelSud::ColKategorie, source_parent);
if (idx.isValid())
accept = sourceModel()->data(idx).toString() == mFilterKategorie;
}
if (accept && !mFilterText.isEmpty())
{
QRegularExpression rx(QRegularExpression::escape(mFilterText), QRegularExpression::CaseInsensitiveOption);
Expand Down Expand Up @@ -241,3 +262,25 @@ bool ProxyModelSud::dateInRange(const QDateTime &dt) const
{
return (!mMinDate.isValid() || dt >= mMinDate) && (!mMaxDate.isValid() || dt <= mMaxDate);
}

void ProxyModelSud::saveSetting(QSettings* settings)
{
settings->setValue("filterSudStatus", (int)filterStatus());
settings->setValue("filterSudMerkliste", filterMerkliste());
settings->setValue("filterSudDate", filterDate());
settings->setValue("filterSudDateVon", filterMinimumDate().date());
settings->setValue("filterSudDateBis", filterMaximumDate().date());
settings->setValue("filterSudKategorie", filterKategorie());
}

void ProxyModelSud::loadSettings(QSettings* settings)
{
setFilterStatus(static_cast<ProxyModelSud::FilterStatus>(settings->value("filterSudStatus", ProxyModelSud::Alle).toInt()));
setFilterMerkliste(settings->value("filterSudMerkliste", false).toBool());
setFilterDate(settings->value("filterSudDate", false).toBool());
QDate minDate = settings->value("filterSudDateVon", QDate::currentDate().addYears(-1)).toDate();
QDate maxDate = settings->value("filterSudDateBis", QDate::currentDate()).toDate();
setFilterMinimumDate(QDateTime(minDate, QTime(1,0,0)));
setFilterMaximumDate(QDateTime(maxDate, QTime(23,59,59)));
setFilterKategorie(settings->value("filterSudKategorie", "").toString());
}
8 changes: 8 additions & 0 deletions kleiner-brauhelfer-core/proxymodelsud.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "proxymodel.h"
#include <QFlag>
#include <QDateTime>
#include <QSettings>

class LIB_EXPORT ProxyModelSud : public ProxyModel
{
Expand Down Expand Up @@ -50,6 +51,12 @@ class LIB_EXPORT ProxyModelSud : public ProxyModel
QString filterText() const;
void setFilterText(const QString& text);

QString filterKategorie() const;
void setFilterKategorie(const QString& kategorie);

void saveSetting(QSettings* settings);
void loadSettings(QSettings* settings);

protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const Q_DECL_OVERRIDE;

Expand All @@ -63,6 +70,7 @@ class LIB_EXPORT ProxyModelSud : public ProxyModel
QDateTime mMinDate;
QDateTime mMaxDate;
QString mFilterText;
QString mFilterKategorie;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(ProxyModelSud::FilterStatus)
Expand Down
2 changes: 2 additions & 0 deletions kleiner-brauhelfer/kleiner-brauhelfer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ SOURCES += \
widgets/datetimeedit.cpp \
widgets/doublespinbox.cpp \
widgets/doublespinboxsud.cpp \
widgets/filterbuttonsud.cpp \
widgets/iconthemed.cpp \
widgets/pushbutton.cpp \
widgets/spinbox.cpp \
Expand Down Expand Up @@ -211,6 +212,7 @@ HEADERS += \
widgets/datetimeedit.h \
widgets/doublespinbox.h \
widgets/doublespinboxsud.h \
widgets/filterbuttonsud.h \
widgets/iconthemed.h \
widgets/pushbutton.h \
widgets/spinbox.h \
Expand Down
Loading

0 comments on commit 86756a5

Please sign in to comment.