Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
chorestore.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <QtCore/QString>
7#include <QtGui/QStandardItemModel>
8
13class ChoreStore : public QStandardItemModel
14{
15public:
17 enum Role {
18 IdRole = Qt::UserRole + 1,
19 };
20
22 explicit ChoreStore(QString path, QObject *parent = nullptr);
23
26 bool load();
28 bool save() const;
29
31 int add(const QString &title);
33 bool remove(int id);
35 int idAt(int row) const;
37 int rowOf(int id) const;
39 int openCount() const;
40
41private:
43 void append(int id, const QString &title, bool done);
44
45 QString m_path;
46 int m_nextId = 1;
47};
bool save() const
Writes the chores to the file. False if it can't be written.
Definition chorestore.cpp:43
bool remove(int id)
Removes the chore with this id. False if there is none.
Definition chorestore.cpp:73
bool load()
Reads the file, replacing the chores in the store.
Definition chorestore.cpp:22
int openCount() const
Chores not yet done.
Definition chorestore.cpp:97
int rowOf(int id) const
The row of the chore with this id, or -1.
Definition chorestore.cpp:88
QString m_path
The JSON file the chores are saved to.
Definition chorestore.h:45
int add(const QString &title)
Adds a chore at the end and returns its id.
Definition chorestore.cpp:65
int idAt(int row) const
The id of the chore in row, or -1.
Definition chorestore.cpp:82
ChoreStore(QString path, QObject *parent=nullptr)
An empty store that saves to path; an empty path saves nowhere.
Definition chorestore.cpp:17
void append(int id, const QString &title, bool done)
Appends an item for a chore.
Definition chorestore.cpp:107
int m_nextId
The id the next new chore gets.
Definition chorestore.h:46
Role
Item data roles of the model, beyond Qt's own.
Definition chorestore.h:17
@ IdRole
The chore's id, an int.
Definition chorestore.h:18