122508 【备份还原】备份名称限制中文、英文均为65位,且无超出长度的提示

This commit is contained in:
zhaominyong 2022-06-16 17:21:44 +08:00
parent a936536f5a
commit 4818e461d4
12 changed files with 749 additions and 610 deletions

View File

@ -0,0 +1,26 @@
#include "inputvalidator.h"
InputValidator::InputValidator(const QRegExp &rx, QObject *parent) :
QRegExpValidator(rx, parent)
{}
InputValidator::~InputValidator()
{}
QValidator::State InputValidator::validate(QString &input, int &pos) const
{
QString in = input;
int index = pos;
State state = QRegExpValidator::validate(in, index);
QChar c;
if (!in.isEmpty())
c = in.at(index - 1);
if (State::Acceptable == state)
emit checked(true, in, index, c);
else
emit checked(false, in, index, c);
return state;
}

View File

@ -0,0 +1,20 @@
#ifndef INPUTVALIDATOR_H
#define INPUTVALIDATOR_H
#include <QRegExpValidator>
class InputValidator : public QRegExpValidator
{
Q_OBJECT
public:
InputValidator(const QRegExp &rx, QObject *parent = nullptr);
virtual ~InputValidator();
public:
virtual QValidator::State validate(QString &input, int &pos) const override;
signals:
void checked(bool valid, QString input, int pos, QChar c) const;
};
#endif // INPUTVALIDATOR_H

View File

@ -46,6 +46,7 @@ HEADERS += \
component/filefilterproxymodelforbackup.h \
component/hoverwidget.h \
component/imageutil.h \
component/inputvalidator.h \
component/linelabel.h \
component/mycheckbox.h \
component/myfileselect.h \
@ -95,6 +96,7 @@ SOURCES += \
component/filefilterproxymodelforbackup.cpp \
component/hoverwidget.cpp \
component/imageutil.cpp \
component/inputvalidator.cpp \
component/linelabel.cpp \
component/mycheckbox.cpp \
component/myfileselect.cpp \

View File

@ -20,6 +20,7 @@
#include "../component/myfileselect.h"
#include "../component/pixmaplabel.h"
#include "../component/pixmapbutton.h"
#include "../component/inputvalidator.h"
#include "../../common/utils.h"
#include "../globalbackupinfo.h"
#include "managebackuppointlist.h"
@ -1174,6 +1175,7 @@ void DataBackup::on_checkEnv_end(int result)
/**
* @brief
*/
#define MAX_LEN_BACKUPNAME 64
void DataBackup::initForthWidget()
{
QWidget *forth = new QWidget;
@ -1240,7 +1242,7 @@ void DataBackup::initForthWidget()
MyLineEdit *editBackupName = new MyLineEdit(forth);
editBackupName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
editBackupName->setMinimumWidth(350);
editBackupName->setMaxLength(64);
editBackupName->setMaxLength(MAX_LEN_BACKUPNAME);
if (m_backupName.isEmpty())
editBackupName->setPlaceholderText(QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"));
else {
@ -1248,8 +1250,8 @@ void DataBackup::initForthWidget()
}
// 支持输入中英文数字和部分字符
// QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9~!@#$%^&*()-_+={}':;'\\[\\].<>/? ¥()——;《》‘’:“”、?]+$"); //其中匹配中文[\u4e00-\u9fa5]
QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9-@& +():']*$");
QValidator *validator = new QRegExpValidator(regx);
QRegExp regx("[^<>,; `|#\\^\\$]+");//regx("^[\u4e00-\u9fa5a-zA-Z0-9-@& +():'()——《》‘’:“”]*$");
InputValidator *validator = new InputValidator(regx);
editBackupName->setValidator(validator);
labelBackupName->setFixedHeight(editBackupName->height());
@ -1279,15 +1281,34 @@ void DataBackup::initForthWidget()
// hlayoutCenterLine2->setAlignment(Qt::AlignCenter);
// vlayout->addLayout(hlayoutCenterLine2);
connect(validator, &InputValidator::checked, this, [=](bool valid, QString in, int pos, QChar c) {
QString text = editBackupName->text();
if (valid) {
if (pos >= MAX_LEN_BACKUPNAME) {
labelError->setDeplayText(tr("Maximum length reached"));
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
} else if (text == in) {
labelError->setVisible(false);
}
} else {
labelError->setDeplayText(tr("Unsupported symbol : ") + c);
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
}
});
connect(editBackupName, &MyLineEdit::textChanged, this, [=](const QString &text) {
if (!text.isEmpty() && text != this->m_backupName && this->isExistsBackupName(text)) {
labelError->setDeplayText(tr("Name already exists"));
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
} else {
} else if (text.isEmpty()) {
labelError->setDeplayText("");
labelError->setVisible(false);
} else {
// 这里面的情况包含在了上面的InputValidator::checked信号处理逻辑中
}
});
connect(this, &DataBackup::clearBackupName, this, [=]() {

View File

@ -140,6 +140,7 @@ void GhostImage::initFirstWidget()
this->m_backupName = "";
SelectRestorePoint * selectDialog = new SelectRestorePoint(this, SelectRestorePoint::SYSTEM, true);
selectDialog->setNeedConfirm(false);
connect(selectDialog, &SelectRestorePoint::selected, this, [=](ParseBackupList::BackupPoint backupPoint){
this->m_uuid = backupPoint.m_uuid;
this->m_backupName = backupPoint.m_backupName;

View File

@ -52,7 +52,7 @@ SelectRestorePoint::SelectRestorePoint(QWidget *parent, BackupPointType backupTy
}
// 还原相应备份点
if (MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Information"), QObject::tr("Do you want to continue?"), QObject::tr("Continue"), QObject::tr("Cancel"))) {
if (!this->m_needConfirm || MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Information"), QObject::tr("Do you want to continue?"), QObject::tr("Continue"), QObject::tr("Cancel"))) {
int curRow = this->m_tableWidget->currentRow();
ParseBackupList::BackupPoint backupPoint;
backupPoint.m_backupName = this->text(curRow, Column_Index::Backup_Name);

View File

@ -15,6 +15,10 @@ public:
explicit SelectRestorePoint(QWidget *parent = nullptr, BackupPointType backupType = BackupPointType::SYSTEM, bool isOnlyShowLocal = false);
virtual ~SelectRestorePoint();
void setNeedConfirm(bool needConfirm) {
m_needConfirm = needConfirm;
}
public slots:
void initTableWidget();
@ -23,6 +27,7 @@ private:
private:
BackupPointType m_backupType;
bool m_needConfirm = true;
};
#endif // SELECTRESTOREPOINT_H

View File

@ -19,6 +19,7 @@
#include "../component/linelabel.h"
#include "../component/ringsprogressbar.h"
#include "../component/pixmaplabel.h"
#include "../component/inputvalidator.h"
#include "../../common/utils.h"
#include "../globalbackupinfo.h"
#include "../gsettingswrapper.h"
@ -720,6 +721,7 @@ void SystemBackup::on_checkEnv_end(int result)
/**
* @brief
*/
#define MAX_LEN_BACKUPNAME 64
void SystemBackup::initForthWidget()
{
QWidget *forth = new QWidget;
@ -790,8 +792,8 @@ void SystemBackup::initForthWidget()
editBackupName->setPlaceholderText(QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"));
// 支持输入中英文数字和部分字符
// QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9~!@#$%^&*()-_+={}':;'\\[\\].<>/? ¥()——;《》‘’:“”、?]+$"); //其中匹配中文[\u4e00-\u9fa5]
QRegExp regx("^[\u4e00-\u9fa5a-zA-Z0-9-@& +():']*$");
QValidator *validator = new QRegExpValidator(regx);
QRegExp regx("[^<>,; `|#\\^\\$]+");//regx("^[\u4e00-\u9fa5a-zA-Z0-9-@& +():'()——《》‘’:“”]*$");
InputValidator *validator = new InputValidator(regx);
editBackupName->setValidator(validator);
labelBackupName->setFixedHeight(editBackupName->height());
@ -810,15 +812,35 @@ void SystemBackup::initForthWidget()
labelError->setFontColor(Qt::red);
labelError->setVisible(false);
labelError->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
connect(validator, &InputValidator::checked, this, [=](bool valid, QString in, int pos, QChar c) {
QString text = editBackupName->text();
if (valid) {
if (pos >= MAX_LEN_BACKUPNAME) {
labelError->setDeplayText(tr("Maximum length reached"));
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
} else if (text == in) {
labelError->setVisible(false);
}
} else {
labelError->setDeplayText(tr("Unsupported symbol : ") + c);
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
}
});
connect(editBackupName, &MyLineEdit::textChanged, this, [=](const QString &text) {
if (!text.isEmpty() && this->isExistsBackupName(text)) {
labelError->setDeplayText(tr("Name already exists"));
labelError->setVisible(true);
labelError->move(editBackupName->geometry().left(), editBackupName->geometry().bottom() + 10);
} else {
} else if (text.isEmpty()) {
labelError->setDeplayText("");
labelError->setVisible(false);
} else {
// 这里面的情况包含在了上面的InputValidator::checked信号处理逻辑中
}
});
connect(this, &SystemBackup::clearBackupName, this, [=]() {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff