#ifndef QSUBSCRIPTIONMANAGER_H #define QSUBSCRIPTIONMANAGER_H #include #include #include #include #include #include #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 getAllSubscriptions() const; double getThreshold(const QString& stockCode) const; bool isSubscribed(const QString& stockCode) const; bool isEnabled(const QString& stockCode) const; void addSubscriptions(const QList& subscriptions); void removeSubscriptions(const QList& 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 m_subscriptions; QString m_configPath; mutable QMutex m_mutex; QString getDefaultConfigPath() const; }; #endif