добавил обработку счетчиков
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// countermanager.h
|
||||
#ifndef COUNTERMANAGER_H
|
||||
#define COUNTERMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include "udatabase.h"
|
||||
|
||||
class CounterManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct Counter {
|
||||
QString name;
|
||||
int count;
|
||||
|
||||
Counter() : count(0) {}
|
||||
Counter(const QString& n, int c = 0) : name(n), count(c) {}
|
||||
|
||||
bool operator==(const QString& otherName) const { return name == otherName; }
|
||||
};
|
||||
|
||||
explicit CounterManager(QObject *parent = nullptr);
|
||||
~CounterManager();
|
||||
|
||||
// Инициализация с базой данных
|
||||
bool initialize(uDataBase *database);
|
||||
|
||||
// Управление счетчиками
|
||||
bool addCounter(const QString &name, int initialValue = 0);
|
||||
bool removeCounter(const QString &name);
|
||||
bool updateCounter(const QString &oldName, const QString &newName, int newValue);
|
||||
bool incrementCounter(const QString &name, int step = 1);
|
||||
bool decrementCounter(const QString &name, int step = 1);
|
||||
int getCount(const QString &name) const;
|
||||
|
||||
// Обработка сообщения: увеличивает счётчики, чьи имена встречаются в тексте
|
||||
void processMessage(const QString &message);
|
||||
|
||||
// Получение всех счётчиков
|
||||
QVector<Counter> getAllCounters() const { return m_counters; }
|
||||
bool contains(const QString &name) const;
|
||||
|
||||
// Сохранение/загрузка в БД
|
||||
bool saveToDatabase();
|
||||
bool loadFromDatabase();
|
||||
|
||||
signals:
|
||||
void dataChanged();
|
||||
void counterAdded(const QString &name, int value);
|
||||
void counterRemoved(const QString &name);
|
||||
void counterUpdated(const QString &oldName, const QString &newName);
|
||||
void counterIncremented(const QString &name, int newValue);
|
||||
|
||||
private:
|
||||
uDataBase *m_database;
|
||||
QVector<Counter> m_counters;
|
||||
|
||||
int findIndex(const QString &name) const;
|
||||
};
|
||||
|
||||
#endif // COUNTERMANAGER_H
|
||||
Reference in New Issue
Block a user