Update 更新文档
This commit is contained in:
55
cleaned_source_code/Sqbase/qsubscriptionmanager.h
Normal file
55
cleaned_source_code/Sqbase/qsubscriptionmanager.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef QSUBSCRIPTIONMANAGER_H
|
||||
#define QSUBSCRIPTIONMANAGER_H
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSharedPointer>
|
||||
#include <QDateTime>
|
||||
#include <QMutex>
|
||||
#include "BZStruct.h"
|
||||
struct SubscriptionConfig {
|
||||
QString stockCode;
|
||||
double threshold;
|
||||
bool enabled;
|
||||
QDateTime lastUpdated;
|
||||
SubscriptionConfig() : threshold(0.0), enabled(true) {}
|
||||
SubscriptionConfig(const QString& code, double thresh, bool en = true)
|
||||
: stockCode(code), threshold(thresh), enabled(en), lastUpdated(QDateTime::currentDateTime()) {}
|
||||
bool operator==(const SubscriptionConfig& other) const {
|
||||
return stockCode == other.stockCode;
|
||||
}
|
||||
};
|
||||
class QSubscriptionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static QSubscriptionManager* instance();
|
||||
bool addSubscription(const QString& stockCode, double threshold);
|
||||
bool removeSubscription(const QString& stockCode);
|
||||
bool updateThreshold(const QString& stockCode, double threshold);
|
||||
bool enableSubscription(const QString& stockCode, bool enabled = true);
|
||||
QList<SubscriptionConfig> getAllSubscriptions() const;
|
||||
double getThreshold(const QString& stockCode) const;
|
||||
bool isSubscribed(const QString& stockCode) const;
|
||||
bool isEnabled(const QString& stockCode) const;
|
||||
void addSubscriptions(const QList<SubscriptionConfig>& subscriptions);
|
||||
void removeSubscriptions(const QList<QString>& stockCodes);
|
||||
void loadFromFile(const QString& filePath = "");
|
||||
void saveToFile(const QString& filePath = "");
|
||||
int getSubscriptionCount() const;
|
||||
int getEnabledSubscriptionCount() const;
|
||||
signals:
|
||||
void subscriptionAdded(const QString& stockCode, double threshold);
|
||||
void subscriptionRemoved(const QString& stockCode);
|
||||
void thresholdUpdated(const QString& stockCode, double threshold);
|
||||
void subscriptionEnabledChanged(const QString& stockCode, bool enabled);
|
||||
void subscriptionsChanged();
|
||||
private:
|
||||
explicit QSubscriptionManager(QObject *parent = nullptr);
|
||||
~QSubscriptionManager();
|
||||
QMap<QString, SubscriptionConfig> m_subscriptions;
|
||||
QString m_configPath;
|
||||
mutable QMutex m_mutex;
|
||||
QString getDefaultConfigPath() const;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user