mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
regexp to validate image title and image name
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
ac2552603b
commit
1ed324fd20
@ -1,4 +1,6 @@
|
||||
#include <QtWidgets>
|
||||
#include <QValidator>
|
||||
#include <QRegExp>
|
||||
#include "vinsertimagedialog.h"
|
||||
|
||||
VInsertImageDialog::VInsertImageDialog(const QString &title, const QString &defaultImageTitle,
|
||||
@ -39,6 +41,9 @@ void VInsertImageDialog::setupUI()
|
||||
imageTitleEdit = new QLineEdit(defaultImageTitle);
|
||||
imageTitleEdit->selectAll();
|
||||
imageTitleLabel->setBuddy(imageTitleEdit);
|
||||
QRegExp regExp("[\\w\\(\\)@#%\\*\\-\\+=\\?<>\\,\\.]+");
|
||||
QValidator *validator = new QRegExpValidator(regExp, this);
|
||||
imageTitleEdit->setValidator(validator);
|
||||
|
||||
okBtn = new QPushButton(tr("&OK"));
|
||||
okBtn->setDefault(true);
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegExp>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
@ -68,13 +67,15 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title,
|
||||
const QString &format)
|
||||
{
|
||||
Q_ASSERT(!title.isEmpty());
|
||||
QRegularExpression regExp("[^a-zA-Z0-9_]+");
|
||||
QRegExp regExp("\\W");
|
||||
QString baseName(title.toLower());
|
||||
baseName.replace(regExp, "_");
|
||||
baseName.remove(regExp);
|
||||
baseName.prepend('_');
|
||||
|
||||
// Add current time to make the name be most likely unique
|
||||
// Add current time and random number to make the name be most likely unique
|
||||
baseName = baseName + '_' + QString::number(QDateTime::currentDateTime().toTime_t());
|
||||
baseName = baseName + '_' + QString::number(qrand());
|
||||
|
||||
QString imageName = baseName + "." + format.toLower();
|
||||
QString filePath = QDir(path).filePath(imageName);
|
||||
int index = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user