Skip to content

Commit

Permalink
remove Qt 5
Browse files Browse the repository at this point in the history
  • Loading branch information
plopop committed Aug 15, 2023
1 parent f773bc0 commit e907217
Show file tree
Hide file tree
Showing 40 changed files with 94 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/core/iconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QJsonArray>
#include <QBitArray>
#include <QDataStream>
#include <QIODevice>

namespace vnotex
{
Expand Down
3 changes: 2 additions & 1 deletion src/core/notebook/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <core/exception.h>
#include "notebook.h"
#include "nodeparameters.h"
#include <QRandomGenerator>

using namespace vnotex;

Expand Down Expand Up @@ -483,7 +484,7 @@ QList<QSharedPointer<File>> Node::collectFiles()

ID Node::generateSignature()
{
return static_cast<ID>(QDateTime::currentDateTime().toSecsSinceEpoch() + (static_cast<qulonglong>(qrand()) << 32));
return static_cast<ID>(QDateTime::currentDateTime().toSecsSinceEpoch() + (static_cast<qulonglong>(QRandomGenerator::global()->generate()) << 32));
}

void Node::checkSignature()
Expand Down
11 changes: 8 additions & 3 deletions src/core/notebook/notebookdatabaseaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,12 @@ bool NotebookDatabaseAccess::updateNodeTags(Node *p_node)
const auto &nodeTags = p_node->getTags();

{
const auto tags = QSet<QString>::fromList(queryNodeTags(p_node->getId()));
QStringList list = queryNodeTags(p_node->getId());
QSet<QString> tags;
for (auto &s : list)
{
tags.insert(s);
}
if (tags.isEmpty() && nodeTags.isEmpty()) {
return true;
}
Expand Down Expand Up @@ -691,7 +696,7 @@ QList<ID> NotebookDatabaseAccess::queryTagNodesRecursive(const QString &p_tag)
}
}

return allIds.toList();
return allIds.values();
}

QStringList NotebookDatabaseAccess::queryTagAndChildren(const QString &p_tag)
Expand Down Expand Up @@ -742,7 +747,7 @@ QStringList NotebookDatabaseAccess::getNodesOfTags(const QStringList &p_tags)
allIds.insert(id);
}
}
nodeIds = allIds.toList();
nodeIds = allIds.values();
}

for (const auto &id : nodeIds) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void VXNotebookConfigMgr::addChildNode(Node *p_parent, const QSharedPointer<Node
QSharedPointer<Node> VXNotebookConfigMgr::loadNodeByPath(const QSharedPointer<Node> &p_root, const QString &p_relativePath)
{
auto p = PathUtils::cleanPath(p_relativePath);
auto paths = p.split('/', QString::SkipEmptyParts);
auto paths = p.split('/', Qt::SkipEmptyParts);
auto node = p_root;
for (auto &pa : paths) {
// Find child @pa in @node.
Expand Down
7 changes: 4 additions & 3 deletions src/export/webviewexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <utils/processutils.h>
#include <utils/htmlutils.h>
#include <core/file.h>
#include <QRegExp>

using namespace vnotex;

Expand Down Expand Up @@ -362,7 +363,7 @@ bool WebViewExporter::embedStyleResources(QString &p_html) const

int pos = 0;
while (pos < p_html.size()) {
int idx = p_html.indexOf(reg, pos);
int idx = reg.indexIn(p_html, pos);
if (idx == -1) {
break;
}
Expand Down Expand Up @@ -393,7 +394,7 @@ bool WebViewExporter::embedBodyResources(const QUrl &p_baseUrl, QString &p_html)

int pos = 0;
while (pos < p_html.size()) {
int idx = p_html.indexOf(reg, pos);
int idx = reg.indexIn(p_html, pos);
if (idx == -1) {
break;
}
Expand Down Expand Up @@ -440,7 +441,7 @@ bool WebViewExporter::fixBodyResources(const QUrl &p_baseUrl,

int pos = 0;
while (pos < p_html.size()) {
int idx = p_html.indexOf(reg, pos);
int idx = reg.indexIn(p_html, pos);
if (idx == -1) {
break;
}
Expand Down
8 changes: 0 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ using namespace vnotex;

void loadTranslators(QApplication &p_app);

void initWebEngineSettings();

void showMessageOnCommandLineIfAvailable(const QString &p_msg);

Expand Down Expand Up @@ -79,7 +78,6 @@ int main(int argc, char *argv[])

Application app(argc, argv);

initWebEngineSettings();

QAccessible::installFactory(&FakeAccessible::accessibleFactory);

Expand Down Expand Up @@ -253,12 +251,6 @@ void loadTranslators(QApplication &p_app)
}
}

void initWebEngineSettings()
{
auto settings = QWebEngineSettings::defaultSettings();
settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
}

void showMessageOnCommandLineIfAvailable(const QString &p_msg)
{
#if defined(Q_OS_WIN)
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5 and above")

equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 12): error("requires Qt 5.12 and above")

QT += core gui widgets webenginewidgets webchannel network svg printsupport
QT += core gui widgets webenginewidgets webchannel network svg printsupport core5compat
QT += sql

CONFIG -= qtquickcompiler
Expand Down
6 changes: 3 additions & 3 deletions src/unitedentry/iunitedentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ void IUnitedEntry::process(const QString &p_args,
initOnFirstProcess();
}

m_askedToStop.store(0);
m_askedToStop.storeRelaxed(0);

return processInternal(p_args, p_popupWidgetFunc);
}

void IUnitedEntry::stop()
{
m_askedToStop.store(1);
m_askedToStop.storeRelaxed(1);
}

bool IUnitedEntry::isAskedToStop() const
{
return m_askedToStop.load() == 1;
return m_askedToStop.loadAcquire() == 1;
}

void IUnitedEntry::setOngoing(bool p_ongoing)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/asyncworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ AsyncWorker::AsyncWorker(QObject *p_parent)

void AsyncWorker::stop()
{
m_askedToStop.store(1);
m_askedToStop.fetchAndStoreAcquire(1);
}

bool AsyncWorker::isAskedToStop() const
{
return m_askedToStop.load() == 1;
return m_askedToStop.loadAcquire() == 1;
}


Expand Down
3 changes: 2 additions & 1 deletion src/utils/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <core/global.h>

#include "pathutils.h"
#include <QRandomGenerator>

using namespace vnotex;

Expand Down Expand Up @@ -313,7 +314,7 @@ QString FileUtils::generateRandomFileName(const QString &p_hints, const QString

// Do not use toSecsSinceEpoch() here since we want a short name.
const QString timeStamp(QDateTime::currentDateTime().toString(QStringLiteral("sszzzmmHHyyMMdd")));
const QString baseName(QString::number(timeStamp.toLongLong() + qrand()));
const QString baseName(QString::number(timeStamp.toLongLong() + QRandomGenerator::global()->generate()));

QString suffix;
if (!p_suffix.isEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/htmlutils.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "htmlutils.h"

#include <QRegExp>
#include <QRegularExpression>

using namespace vnotex;

bool HtmlUtils::hasOnlyImgTag(const QString &p_html)
{
// Tricky.
QRegExp reg(QStringLiteral("<(?:p|span|div) "));
QRegularExpression reg(QStringLiteral("<(?:p|span|div) "));
return !p_html.contains(reg);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/iconutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ QString IconUtils::replaceForegroundOfIcon(const QString &p_iconContent, const Q
}

// Negative lookahead to avoid fill="none".
QRegExp styleRe(R"((\s|"|;)(fill|stroke)(:|(="))(?!none)[^;"]*)");
QRegularExpression styleRe(R"((\s|"|;)(fill|stroke)(:|(="))(?!none)[^;"]*)");
if (p_iconContent.indexOf(styleRe) > -1) {
auto newContent(p_iconContent);
newContent.replace(styleRe, QString("\\1\\2\\3%1").arg(p_foreground));
Expand All @@ -85,7 +85,7 @@ bool IconUtils::isMonochrome(const QString &p_iconContent)
QString lastColor = "";
int pos = 0;
while (pos < p_iconContent.size()) {
int idx = p_iconContent.indexOf(monoRe, pos);
int idx = monoRe.indexIn(p_iconContent, pos);
if (idx == -1) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/printutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ QSharedPointer<QPrinter> PrintUtils::promptForPrint(bool p_printSelectionEnabled

QPrintDialog dialog(printer.data(), p_parent);
if (p_printSelectionEnabled) {
dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
dialog.setOption(QAbstractPrintDialog::PrintSelection);
}

if (dialog.exec() == QDialog::Accepted) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void Utils::appendMsg(QString &p_msg, const QString &p_new)

QString Utils::dateTimeString(const QDateTime &p_dateTime)
{
return p_dateTime.date().toString(Qt::DefaultLocaleLongDate)
return p_dateTime.date().toString(Qt::ISODate)
+ " "
+ p_dateTime.time().toString(Qt::TextDate);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.pri
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += widgets svg
QT += widgets svg core5compat

SOURCES += \
$$PWD/asyncworker.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/utils/webutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ QString WebUtils::toDataUri(const QUrl &p_url, bool p_keepTitle)

if (!p_keepTitle) {
// Remove <title>...</title>.
QRegExp reg("<title>.*</title>", Qt::CaseInsensitive);
QRegularExpression reg("<title>.*</title>");
reg.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
uri.remove(reg);
}
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/utils/widgetutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QStyle>
#include <QAbstractScrollArea>
#include <QScrollBar>
#include <QDesktopWidget>
#include <QApplication>
#include <QDesktopServices>
#include <QKeyEvent>
Expand Down Expand Up @@ -71,8 +70,7 @@ bool WidgetUtils::isScrollBarVisible(QAbstractScrollArea *p_widget, bool p_horiz

QSize WidgetUtils::availableScreenSize(QWidget *p_widget)
{
auto geo = QApplication::desktop()->availableGeometry(p_widget);
return geo.size();
return p_widget->screen()->availableGeometry().size();
}

void WidgetUtils::openUrlByDesktop(const QUrl &p_url)
Expand Down Expand Up @@ -374,7 +372,7 @@ QString WidgetUtils::getMonospaceFont()
for (const auto &candidate : candidates) {
QString family = candidate.trimmed().toLower();
for (auto availFamily : availFamilies) {
availFamily.remove(QRegExp("\\[.*\\]"));
availFamily.remove(QRegularExpression("\\[.*\\]"));
if (family == availFamily.trimmed().toLower()) {
font = availFamily;
return font;
Expand Down
1 change: 0 additions & 1 deletion src/widgets/dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <QVBoxLayout>
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
#include <QScrollBar>
#include <QTimer>
#include <QPlainTextEdit>
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dialogs/imageinsertdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <QRegularExpression>
#include <QLabel>
#include <QPushButton>
#include <QRegExpValidator>
#include <QRegularExpressionValidator>
#include <QSpinBox>
#include <QSlider>
#include <QScrollArea>
Expand Down Expand Up @@ -88,7 +88,7 @@ void ImageInsertDialog::setupUI(const QString &p_title,

// Image Title.
m_imageTitleEdit = WidgetsFactory::createLineEdit(p_imageTitle, mainWidget);
auto titleValidator = new QRegExpValidator(QRegExp(vte::MarkdownUtils::c_imageTitleRegExp), m_imageTitleEdit);
auto titleValidator = new QRegularExpressionValidator(QRegularExpression(vte::MarkdownUtils::c_imageTitleRegExp), m_imageTitleEdit);
m_imageTitleEdit->setValidator(titleValidator);
gridLayout->addWidget(new QLabel(tr("Title:"), mainWidget), 1, 0, 1, 1);
gridLayout->addWidget(m_imageTitleEdit, 1, 1, 1, 3);
Expand All @@ -97,7 +97,7 @@ void ImageInsertDialog::setupUI(const QString &p_title,

// Image Alt.
m_imageAltEdit = WidgetsFactory::createLineEdit(p_imageAlt, mainWidget);
auto altValidator = new QRegExpValidator(QRegExp(vte::MarkdownUtils::c_imageAltRegExp), m_imageAltEdit);
auto altValidator = new QRegularExpressionValidator(QRegularExpression(vte::MarkdownUtils::c_imageAltRegExp), m_imageAltEdit);
m_imageAltEdit->setValidator(altValidator);
gridLayout->addWidget(new QLabel(tr("Alt text:"), mainWidget), 2, 0, 1, 1);
gridLayout->addWidget(m_imageAltEdit, 2, 1, 1, 3);
Expand Down
1 change: 0 additions & 1 deletion src/widgets/dialogs/scrolldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QVBoxLayout>
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
#include <QScrollBar>
#include <QTimer>
#include <QPlainTextEdit>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dialogs/selectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void SelectDialog::addSelection(const QString &p_selectStr, int p_selectID)
QChar shortcut;
if (m_nextShortcut < c_cancelShortcut) {
shortcut = m_nextShortcut;
m_nextShortcut = m_nextShortcut.toLatin1() + 1;
m_nextShortcut = QChar(m_nextShortcut.toLatin1() + 1);
}
const auto icon = IconUtils::drawTextIcon(shortcut, m_shortcutIconForeground, m_shortcutIconBorder);
QListWidgetItem *item = new QListWidgetItem(icon, p_selectStr);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dialogs/settings/fileassociationpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool FileAssociationPage::saveInternal()
if (name.isEmpty()) {
continue;
}
auto suffixes = lineEdit->text().split(c_suffixSeparator, QString::SkipEmptyParts);
auto suffixes = lineEdit->text().split(c_suffixSeparator, Qt::SkipEmptyParts);
fileTypeSuffixes.push_back(CoreConfig::FileTypeSuffix(name, Utils::toLower(suffixes)));
}

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/dialogs/sortdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void SortDialog::updateTreeWidget()
item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
}

m_treeWidget->sortByColumn(-1);
m_treeWidget->sortByColumn(-1, Qt::AscendingOrder);
m_treeWidget->setSortingEnabled(true);
}

Expand Down Expand Up @@ -151,7 +151,7 @@ void SortDialog::handleMoveOperation(MoveOperation p_op)
Q_ASSERT(first <= last && (last - first + 1) == selectedItems.size());
QTreeWidgetItem *firstItem = nullptr;

m_treeWidget->sortByColumn(-1);
m_treeWidget->sortByColumn(-1, Qt::AscendingOrder);

switch (p_op) {
case MoveOperation::Top:
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/dialogs/tableinsertdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ void TableInsertDialog::setupUI(const QString &p_title)
buttonGroup->addButton(rightBtn, static_cast<int>(Alignment::Right));

noneBtn->setChecked(true);
connect(buttonGroup, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
connect(buttonGroup, (void(QButtonGroup::*)(int, bool))(&QButtonGroup::buttonToggled),


this, [this](int p_id, bool p_checked){
if (p_checked) {
m_alignment = static_cast<Alignment>(p_id);
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/editors/markdowneditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <imagehost/imagehostutils.h>
#include <imagehost/imagehost.h>
#include <imagehost/imagehostmgr.h>
#include <QRegExp>

#include "previewhelper.h"
#include "../outlineprovider.h"
Expand Down Expand Up @@ -1198,7 +1199,7 @@ void MarkdownEditor::handleHtmlToMarkdownData(quint64 p_id, TimeStamp p_timeStam

static QString purifyImageTitle(QString p_title)
{
return p_title.remove(QRegExp("[\\r\\n\\[\\]]"));
return p_title.remove(QRegularExpression("[\\r\\n\\[\\]]"));
}

void MarkdownEditor::fetchImagesToLocalAndReplace(QString &p_text)
Expand Down
Loading

0 comments on commit e907217

Please sign in to comment.