From 423043d431829fe8e631f228b5351a6bc49b475a Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 6 Mar 2021 13:13:31 +0100 Subject: [PATCH] Qt6 migration --- core/RunControllableTask.h | 5 ++- core/SqlLexer.cpp | 45 +++++++++-------------- ctk/ctkBasePopupWidget.cpp | 1 - ctk/ctkPopupWidget.cpp | 4 +- ctk/ctkPopupWidget.h | 12 +++--- pglab/BackupDialog.h | 1 - pglab/ColumnTableModel.cpp | 4 +- pglab/DatabaseWindow.cpp | 16 ++++---- pglab/PgLabItemDelegate.cpp | 4 +- pglab/QueryExplainModel.cpp | 6 +-- pglab/QueryTool.cpp | 16 ++++---- pglab/ResultTableModelUtil.cpp | 2 +- pglab/SequenceModel.h | 2 +- pglab/UserConfiguration.cpp | 1 - pglablib/ConnectionConfig.cpp | 8 ---- pglablib/FormatToStream.cpp | 6 +-- pglablib/codebuilder/StringEscapeRule.cpp | 4 +- pglablib/util.cpp | 6 +-- pgsql/Pgsql_Params.cpp | 8 ++-- 19 files changed, 64 insertions(+), 87 deletions(-) diff --git a/core/RunControllableTask.h b/core/RunControllableTask.h index e696334..270e095 100644 --- a/core/RunControllableTask.h +++ b/core/RunControllableTask.h @@ -40,9 +40,10 @@ public: this->reportResult(result); } } catch (QException &e) { - reportException(e); + QFutureInterfaceBase::reportException(e); } catch (...) { - reportException(QUnhandledException()); + QUnhandledException ex; + QFutureInterfaceBase::reportException(ex); } this->reportFinished(); diff --git a/core/SqlLexer.cpp b/core/SqlLexer.cpp index f309d38..8ad4e49 100644 --- a/core/SqlLexer.cpp +++ b/core/SqlLexer.cpp @@ -100,8 +100,7 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent } length = m_pos - startpos; tokentype = BasicTokenType::WhiteSpace; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); + out = m_block.mid(startpos, length); return true; } } @@ -117,8 +116,7 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent } length = m_pos - startpos; tokentype = BasicTokenType::Comment; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); + out = m_block.mid(startpos, length); return true; } else if (c == ':') { @@ -127,9 +125,8 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent nextChar(); length = m_pos - startpos; tokentype = BasicTokenType::Cast; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } } else if (isSelf(c)) { @@ -139,9 +136,8 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent else tokentype = BasicTokenType::Self; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } else if (isOperatorChar(c)) { while (true) { @@ -153,27 +149,24 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent // unexpected end, pretend nothings wrong length = m_pos - startpos; tokentype = BasicTokenType::Operator; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } } } else if (c == '\'') { // Single quoted string so it's an SQL text literal if (parseSingleQuotedString(startpos, length, tokentype)) { - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } return false; } else if (c == '"') { // Double quoted identifier if (parseDoubleQuotedIdentifier(startpos, length, tokentype)) { - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } return false; } @@ -200,9 +193,8 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent } length = m_pos - startpos; tokentype = BasicTokenType::Symbol; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); - return true; + out = m_block.mid(startpos, length); + return true; } // } // else if (LexerState::InBlockComment == m_state) { @@ -301,8 +293,7 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token } tokentype = BasicTokenType::Parameter; length = m_pos - startpos; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); + out = m_block.mid(startpos, length); return true; } @@ -314,8 +305,7 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token // Found valid dollar quote tokentype = BasicTokenType::DollarQuote; length = m_pos - startpos; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); + out = m_block.mid(startpos, length); return true; } @@ -323,8 +313,7 @@ bool SqlLexer::parseDollarQuote(int startpos, int &length, BasicTokenType &token // ERROR, unallowed character tokentype = BasicTokenType::None; length = m_pos - startpos; - QStringRef sr(&m_block, startpos, length); - out = sr.toString(); + out = m_block.mid(startpos, length); return false; } } diff --git a/ctk/ctkBasePopupWidget.cpp b/ctk/ctkBasePopupWidget.cpp index 2d03489..7c11e30 100644 --- a/ctk/ctkBasePopupWidget.cpp +++ b/ctk/ctkBasePopupWidget.cpp @@ -21,7 +21,6 @@ // Qt includes #include #include -#include #include #include #include diff --git a/ctk/ctkPopupWidget.cpp b/ctk/ctkPopupWidget.cpp index 1015547..3ad6aae 100644 --- a/ctk/ctkPopupWidget.cpp +++ b/ctk/ctkPopupWidget.cpp @@ -20,7 +20,7 @@ // Qt includes #include -#include +//#include #include #include #include @@ -416,7 +416,7 @@ void ctkPopupWidget::leaveEvent(QEvent* event) } // -------------------------------------------------------------------------- -void ctkPopupWidget::enterEvent(QEvent* event) +void ctkPopupWidget::enterEvent(QEnterEvent* event) { Q_D(ctkPopupWidget); QTimer::singleShot(d->ShowDelay, this, SLOT(updatePopup())); diff --git a/ctk/ctkPopupWidget.h b/ctk/ctkPopupWidget.h index 99675c5..c23dd88 100644 --- a/ctk/ctkPopupWidget.h +++ b/ctk/ctkPopupWidget.h @@ -109,21 +109,21 @@ public Q_SLOTS: public: /// Reimplemented for internal reasons - virtual void hidePopup(); + virtual void hidePopup() override; protected: - virtual void leaveEvent(QEvent* event); - virtual void enterEvent(QEvent* event); - virtual bool eventFilter(QObject* obj, QEvent* event); + virtual void leaveEvent(QEvent* event) override; + virtual void enterEvent(QEnterEvent* event) override; + virtual bool eventFilter(QObject* obj, QEvent* event) override; /// Widget the popup is attached to. It opens right under \a baseWidget /// and if the ctkPopupWidget sizepolicy contains the growFlag/shrinkFlag, /// it tries to resize itself to fit the same width of \a baseWidget. - virtual void setBaseWidget(QWidget* baseWidget); + virtual void setBaseWidget(QWidget* baseWidget) override; protected Q_SLOTS: void updatePopup(); - virtual void onEffectFinished(); + virtual void onEffectFinished() override; private: Q_DECLARE_PRIVATE(ctkPopupWidget); diff --git a/pglab/BackupDialog.h b/pglab/BackupDialog.h index 104a296..63b3d98 100644 --- a/pglab/BackupDialog.h +++ b/pglab/BackupDialog.h @@ -6,7 +6,6 @@ #include "ConnectionConfig.h" #include -class QStringList; class QLabel; class QPushButton; diff --git a/pglab/ColumnTableModel.cpp b/pglab/ColumnTableModel.cpp index 7a9cef5..ee3be5a 100644 --- a/pglab/ColumnTableModel.cpp +++ b/pglab/ColumnTableModel.cpp @@ -298,9 +298,9 @@ QVariant ColumnTableModel::data(const QModelIndex &index, int role) const QVariant v; int col = index.column(); if (col == NullCol || col >= colCount) - v = Qt::AlignCenter + Qt::AlignVCenter; + v = int(Qt::AlignCenter | Qt::AlignVCenter); else - v = Qt::AlignLeft + Qt::AlignVCenter; + v = int(Qt::AlignLeft | Qt::AlignVCenter); return v; } return BaseTableModel::data(index, role); diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index 832fe02..6b7db85 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -141,21 +141,21 @@ void DatabaseWindow::createActions() icon.addFile(QString::fromUtf8(":/icons/page_white_delete.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionClose = new QAction(icon, tr("Close"), this); action->setObjectName("actionClose"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_W)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_W)); } { QIcon icon; icon.addFile(QString::fromUtf8(":/icons/page_white_copy.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionCopy = new QAction(icon, tr("Copy"), this); action->setObjectName("actionCopy"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C)); } { QIcon icon; icon.addFile(QString::fromUtf8(":/icons/token_shortland_character.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionCopyAsCString = new QAction(icon, tr("Copy as C string"), this); action->setObjectName("actionCopyAsCString"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C)); } { QIcon icon; @@ -184,7 +184,7 @@ void DatabaseWindow::createActions() icon.addFile(QString::fromUtf8(":/icons/lightbulb.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionExplainAnalyze = new QAction(icon, tr("Explain analyze"), this); action->setObjectName("actionExplainAnalyze"); - action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F7)); + action->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_F7)); } { QIcon icon; @@ -219,21 +219,21 @@ void DatabaseWindow::createActions() icon.addFile(QString::fromUtf8(":/icons/new_query_tab.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionNewSql = new QAction(icon, tr("New Query"), this); action->setObjectName("actionNewSql"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); } { QIcon icon; icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionOpenSql = new QAction(icon, tr("Open Query"), this); action->setObjectName("actionOpenSql"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O)); } { QIcon icon; //icon.addFile(QString::fromUtf8(":/icons/folder.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionPasteLangString = new QAction(icon, tr("Paste lang string"), this); action->setObjectName("actionPasteLangString"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_V)); } { QIcon icon; @@ -253,7 +253,7 @@ void DatabaseWindow::createActions() icon.addFile(QString::fromUtf8(":/icons/script_save.png"), QSize(), QIcon::Normal, QIcon::On); auto action = actionSaveSql = new QAction(icon, tr("Save query"), this); action->setObjectName("actionSaveSql"); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); } { auto action = actionSaveSqlAs = new QAction(tr("Save query as"), this); diff --git a/pglab/PgLabItemDelegate.cpp b/pglab/PgLabItemDelegate.cpp index 40b1a88..6340734 100644 --- a/pglab/PgLabItemDelegate.cpp +++ b/pglab/PgLabItemDelegate.cpp @@ -103,10 +103,10 @@ void PgLabItemDelegate::initStyleOption(QStyleOptionViewItem *option, option->text = FormatBoolForDisplay(value.toBool()); else { auto str = value.toString(); - auto s = str.leftRef(100); + auto s = str.left(100); // auto f = s.indexOf('\n'); // option->text = ((f > 0) ? s.left(f) : s).toString(); - option->text = s.toString(); + option->text = s; } } else { diff --git a/pglab/QueryExplainModel.cpp b/pglab/QueryExplainModel.cpp index 212e750..38cf1d1 100644 --- a/pglab/QueryExplainModel.cpp +++ b/pglab/QueryExplainModel.cpp @@ -54,13 +54,13 @@ if (role == Qt::DisplayRole) { } else if (role == Qt::TextAlignmentRole) { if (col == c_ColumnNode || col == c_ColumnDetails) { - result = Qt::AlignLeft + Qt::AlignVCenter; + result = int(Qt::AlignLeft | Qt::AlignVCenter); } else { - result = Qt::AlignRight + Qt::AlignVCenter; + result = int(Qt::AlignRight | Qt::AlignVCenter); } } - else if (role == Qt::BackgroundColorRole) { + else if (role == Qt::BackgroundRole) { if (col == c_ColumnExclusive || col == c_ColumnInclusive) { float t = col == 1 ? item->exclusiveTime() : item->inclusiveTime(); float tt = explain->plan->inclusiveTime(); diff --git a/pglab/QueryTool.cpp b/pglab/QueryTool.cpp index ee0dd7c..2dbd502 100644 --- a/pglab/QueryTool.cpp +++ b/pglab/QueryTool.cpp @@ -7,8 +7,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -90,12 +90,9 @@ bool QueryTool::load(const QString &filename) QFile file(filename); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = file.readAll(); - const char *ptr = ba.constData(); - - QTextCodec *codec = QTextCodec::codecForUtfText(ba, QTextCodec::codecForName("utf-8")); - QTextCodec::ConverterState state; - QString text = codec->toUnicode(ptr, ba.size(), &state); - if (state.invalidChars > 0) { + auto toUtf16 = QStringDecoder(QStringDecoder::Utf8); + QString text = toUtf16(ba); + if (toUtf16.hasError()) { file.reset(); QTextStream stream(&file); text = stream.readAll(); @@ -280,8 +277,9 @@ bool QueryTool::saveSqlTo(const QString &filename) QFile file(filename); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); - stream.setCodec("utf-8"); - QString text = ui->queryEdit->toPlainText(); + //stream.setCodec("utf-8"); + stream.setEncoding(QStringConverter::Utf8); + QString text = ui->queryEdit->toPlainText(); stream << text; stream.flush(); diff --git a/pglab/ResultTableModelUtil.cpp b/pglab/ResultTableModelUtil.cpp index fb0b8c6..cedb21c 100644 --- a/pglab/ResultTableModelUtil.cpp +++ b/pglab/ResultTableModelUtil.cpp @@ -8,7 +8,7 @@ using namespace Pgsql; Qt::Alignment GetDefaultAlignmentForType(Oid o) { - int r; + Qt::Alignment r; switch (o) { case int2_oid: case int4_oid: diff --git a/pglab/SequenceModel.h b/pglab/SequenceModel.h index 00aa7d3..734f80c 100644 --- a/pglab/SequenceModel.h +++ b/pglab/SequenceModel.h @@ -34,7 +34,7 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; void setCatalog(std::shared_ptr cat); - void SequenceModel::setNamespaceFilter(NamespaceFilter filter); + void setNamespaceFilter(NamespaceFilter filter); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; diff --git a/pglab/UserConfiguration.cpp b/pglab/UserConfiguration.cpp index 2cecd67..cea1be2 100644 --- a/pglab/UserConfiguration.cpp +++ b/pglab/UserConfiguration.cpp @@ -10,7 +10,6 @@ UserConfiguration* UserConfiguration::instance() UserConfiguration::UserConfiguration() : m_settings(nullptr) { - m_settings.setIniCodec("UTF-8"); } QFont UserConfiguration::codeFont() const diff --git a/pglablib/ConnectionConfig.cpp b/pglablib/ConnectionConfig.cpp index f19edee..c1d1d02 100644 --- a/pglablib/ConnectionConfig.cpp +++ b/pglablib/ConnectionConfig.cpp @@ -7,14 +7,6 @@ namespace { - class registerMetaTypes { - public: - registerMetaTypes() - { - qRegisterMetaTypeStreamOperators("ConnectionConfig"); - } - } registerMetaTypes_instance; - struct { SslMode mode; const char* string; diff --git a/pglablib/FormatToStream.cpp b/pglablib/FormatToStream.cpp index f8615bc..56b7f7f 100644 --- a/pglablib/FormatToStream.cpp +++ b/pglablib/FormatToStream.cpp @@ -5,7 +5,7 @@ void FormatToStream(QTextStream &stream, QString format, std::function field_callback) { // Use static to optimize only once - static QRegularExpression cached_find_var_re("(?:[^\\\\]|^)(\\/%([a-zA-Z0-9_-]+)%\\/)", QRegularExpression::OptimizeOnFirstUsageOption); + static QRegularExpression cached_find_var_re("(?:[^\\\\]|^)(\\/%([a-zA-Z0-9_-]+)%\\/)"); int from = 0; QRegularExpressionMatch match; @@ -17,7 +17,7 @@ void FormatToStream(QTextStream &stream, QString format, std::function 0) { QString clipboard_string; - QTextStream out(&clipboard_string, QIODevice::WriteOnly); + QTextStream out(&clipboard_string, QTextStream::WriteOnly); CsvWriter csv(&out); csv.setSeperator('\t'); csv.setQuote('"'); @@ -153,7 +153,7 @@ QString ConvertToMultiLineCString(const QString &in_) if (token.ok) { if (token.tokenType == BasicTokenType::Comment) { // save comment is seperate variable - comment = "//" + token.out.rightRef(token.out.length()-2); + comment = "//" + token.out.right(token.out.length()-2); // Trim whitespace on right int idx; for (idx = comment.length() - 1; idx >= 0 && comment[idx].isSpace(); --idx) ; @@ -168,7 +168,7 @@ QString ConvertToMultiLineCString(const QString &in_) ++idx; if (!comment.isEmpty()) { // put the whitespace in front of the comment so it will be outside the contents of the string literal but alignment of comments is preserved - comment = line.rightRef(line.length() - (idx)) + comment; + comment = line.right(line.length() - (idx)) + comment; } line.truncate(idx); } diff --git a/pgsql/Pgsql_Params.cpp b/pgsql/Pgsql_Params.cpp index 6fe88d2..7ac9c7c 100644 --- a/pgsql/Pgsql_Params.cpp +++ b/pgsql/Pgsql_Params.cpp @@ -56,9 +56,9 @@ Param Params::addText(const char *data, Oid oid) { m_paramTypes.push_back(oid); m_paramValues.push_back(data); - m_paramLengths.push_back(data ? strlen(data) + 1 : 0); + m_paramLengths.push_back(data ? static_cast(strlen(data)) + 1 : 0); m_paramFormats.push_back(0); - return Param(*this, m_paramValues.size() - 1); + return Param(*this, static_cast(m_paramValues.size()) - 1); } Param Params::add(const QString &s, Oid oid) @@ -76,7 +76,7 @@ Param Params::add(const char *data, Oid oid) char * p = nullptr; int len = 0; if (data) { - len = std::strlen(data); + len = static_cast(std::strlen(data)); p = new char[len+1]; std::memcpy(p, data, len); p[len] = 0; @@ -108,7 +108,7 @@ void Params::clear() void Params::copyValues(const t_paramValues &r) { - const int n = m_paramTypes.size(); + const int n = static_cast(m_paramTypes.size()); m_paramValues.reserve(n); for (int i = 0; i < n; ++i) { if (r[i]) {