93 lines
2.1 KiB
C++
93 lines
2.1 KiB
C++
#ifndef TIMESLOTCONFIG_H
|
|
#define TIMESLOTCONFIG_H
|
|
|
|
#include <QString>
|
|
#include <QTime>
|
|
#include <QVector>
|
|
#include <QSettings>
|
|
|
|
/**
|
|
* @brief 签到时间段结构
|
|
*/
|
|
struct TimeSlot
|
|
{
|
|
QString name; // 时段名称(如:上午签到)
|
|
QTime startTime; // 开始时间
|
|
QTime endTime; // 结束时间
|
|
bool enabled; // 是否启用
|
|
|
|
TimeSlot()
|
|
: enabled(true)
|
|
{}
|
|
|
|
TimeSlot(const QString &n, const QTime &start, const QTime &end, bool en = true)
|
|
: name(n), startTime(start), endTime(end), enabled(en)
|
|
{}
|
|
|
|
// 检查给定时间是否在此时段内
|
|
bool isInRange(const QTime &time) const {
|
|
if (!enabled) return false;
|
|
return time >= startTime && time <= endTime;
|
|
}
|
|
|
|
QString toString() const {
|
|
return QString("%1: %2 - %3 %4")
|
|
.arg(name)
|
|
.arg(startTime.toString("HH:mm"))
|
|
.arg(endTime.toString("HH:mm"))
|
|
.arg(enabled ? "(启用)" : "(禁用)");
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @brief 时间段配置管理类
|
|
*/
|
|
class TimeSlotConfig
|
|
{
|
|
public:
|
|
static TimeSlotConfig& instance();
|
|
|
|
// 获取所有时间段
|
|
QVector<TimeSlot> getTimeSlots() const { return m_timeSlots; }
|
|
|
|
// 设置时间段
|
|
void setTimeSlots(const QVector<TimeSlot> &timeSlots);
|
|
|
|
// 添加时间段
|
|
void addTimeSlot(const TimeSlot &timeSlot);
|
|
|
|
// 删除时间段
|
|
void removeTimeSlot(int index);
|
|
|
|
// 更新时间段
|
|
void updateTimeSlot(int index, const TimeSlot &timeSlot);
|
|
|
|
// 检查时间是否在任何启用的时段内
|
|
bool isValidTime(const QTime &time) const;
|
|
|
|
// 获取当前时段名称
|
|
QString getCurrentTimeSlotName(const QTime &time) const;
|
|
|
|
// 保存配置到文件
|
|
void saveToFile();
|
|
|
|
// 从文件加载配置
|
|
void loadFromFile();
|
|
|
|
// 重置为默认配置
|
|
void resetToDefault();
|
|
|
|
private:
|
|
TimeSlotConfig();
|
|
~TimeSlotConfig();
|
|
TimeSlotConfig(const TimeSlotConfig&) = delete;
|
|
TimeSlotConfig& operator=(const TimeSlotConfig&) = delete;
|
|
|
|
QVector<TimeSlot> m_timeSlots;
|
|
QString m_configFilePath;
|
|
|
|
void initDefaultTimeSlots();
|
|
};
|
|
|
|
#endif // TIMESLOTCONFIG_H
|