农历日历 v1.0.4
载入中...
搜索中...
未找到
LunarTable.h
1
6#ifndef LUNARTABLE_H
7#define LUNARTABLE_H
8
9#include <QObject>
10#include <QDate>
11#include <QMap>
12#include <QFile>
13#include <QMutex>
14
20class CLunarTable : public QObject
21{
22 Q_OBJECT
23public:
24 static CLunarTable* Instance();
25
27 {
28 quint8 nTg;
29 quint8 nDz;
30 bool bLeap; //是闰月
31 int nYear;
32 quint8 nMonth;
33 quint8 nDay;
34 qint8 nJq;
35 };
36
46 int GetLunar(const QDate &date, _LUNAR_DAY &lunar, bool cache = true);
47
48 int Load(const QString &file);
49 int Save(const QString &file, bool bAll = true);
50
51 int Generate(const QDate &min, const QDate &max, const QString& szFile, int nThread = 2, bool bClearCache = false, bool bSaveAllDate = true);
52 int Generate(const QDate &min, const QDate &max, bool bUseCached);
53
54public Q_SLOTS:
55 void slotGenerateFinished();
56
57private:
58 explicit CLunarTable(QObject *parent = nullptr);
59 int LoadVersion0(QDataStream &data);
60 int CleanOutsideRange(const QDate&min, const QDate& max);
61
62 QMap<qint64, _LUNAR_DAY> m_Lunar;
63 QMutex m_GenerateMutex;
64 QString m_szFile;
65 QBasicAtomicInt m_nThreadNumber;
66 QDate m_minDate, m_maxDate;
67 bool m_bSaveAllDate;
68};
69
70#include <QThread>
71
72class CThreadGenerate: public QThread
73{
74 Q_OBJECT
75public:
76 explicit CThreadGenerate(CLunarTable* pTable,
77 const QDate& min,
78 const QDate& max,
79 bool bCached,
80 QObject *parent = nullptr);
81
82protected:
83 virtual void run();
84
85private:
86 CLunarTable* m_pTable;
87 QDate m_minDate, m_maxDate;
88 bool m_bCached;
89};
90
91#endif // LUNARTABLE_H
产生、保存、加载农历缓存。用于提高性能。
Definition LunarTable.h:21
int GetLunar(const QDate &date, _LUNAR_DAY &lunar, bool cache=true)
得到指定日期的农历