yhkylin-backup-tools/kybackup/component/backuplistwidget.h

65 lines
1.5 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef REMOVABLELISTWIDGET_H
#define REMOVABLELISTWIDGET_H
#include <QListWidget>
#include <QStringList>
#include <QDropEvent>
#include <QLabel>
class MyItemWidget : public QWidget
{
Q_OBJECT
public:
explicit MyItemWidget(QWidget* parent = nullptr);
virtual ~MyItemWidget();
signals:
void selected(bool checked);
};
class BackupListWidget : public QListWidget
{
Q_OBJECT
public:
explicit BackupListWidget(QWidget *parent = nullptr);
virtual ~BackupListWidget();
// 添加列表项注意使用本类的功能不能用addItem等基类添加项的方法
bool appendItem(const QString &text);
// 判断列表项是否包含text注意使用时不能用findItems等基类查找方法
bool contains(const QString &text);
// 获取备份路径列表
QStringList getBackupPaths() { return m_List; }
// 设置备份路径限制为只能是pathLimit或其子路径
void setPathLimit(const QStringList &pathLimit) { m_pathLimit.append(pathLimit); }
// 清空
void clearData() {
this->clear();
this->m_List.clear();
emit this->deleteEmpty();
}
protected:
void dropEvent(QDropEvent *e);
signals:
void deleteEmpty();
void addedItem();
private:
bool checkPathLimit(const QString &path);
private:
QLabel *m_plusLogo;
QLabel *m_plusText;
int m_type = QListWidgetItem::ItemType::UserType + 1;
QStringList m_List;
QStringList m_pathLimit;
};
#endif // REMOVABLELISTWIDGET_H