Qt6 migration

This commit is contained in:
eelke 2021-03-06 13:13:31 +01:00
parent 87553b2554
commit 423043d431
19 changed files with 64 additions and 87 deletions

View file

@ -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();

View file

@ -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,8 +125,7 @@ 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();
out = m_block.mid(startpos, length);
return true;
}
}
@ -139,8 +136,7 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
else
tokentype = BasicTokenType::Self;
QStringRef sr(&m_block, startpos, length);
out = sr.toString();
out = m_block.mid(startpos, length);
return true;
}
else if (isOperatorChar(c)) {
@ -153,8 +149,7 @@ 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();
out = m_block.mid(startpos, length);
return true;
}
}
@ -162,8 +157,7 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
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();
out = m_block.mid(startpos, length);
return true;
}
return false;
@ -171,8 +165,7 @@ bool SqlLexer::nextBasicToken(int &startpos, int &length, BasicTokenType &tokent
else if (c == '"') {
// Double quoted identifier
if (parseDoubleQuotedIdentifier(startpos, length, tokentype)) {
QStringRef sr(&m_block, startpos, length);
out = sr.toString();
out = m_block.mid(startpos, length);
return true;
}
return false;
@ -200,8 +193,7 @@ 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();
out = m_block.mid(startpos, length);
return true;
}
// }
@ -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;
}
}

View file

@ -21,7 +21,6 @@
// Qt includes
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QDir>
#include <QEvent>
#include <QLabel>

View file

@ -20,7 +20,7 @@
// Qt includes
#include <QApplication>
#include <QDesktopWidget>
//#include <QDesktopWidget>
#include <QDialog>
#include <QDir>
#include <QEvent>
@ -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()));

View file

@ -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);

View file

@ -6,7 +6,6 @@
#include "ConnectionConfig.h"
#include <QProcess>
class QStringList;
class QLabel;
class QPushButton;

View file

@ -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);

View file

@ -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);

View file

@ -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 {

View file

@ -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();

View file

@ -7,8 +7,8 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QStatusBar>
#include <QStringConverter>
#include <QTabWidget>
#include <QTextCodec>
#include <QTextDocumentFragment>
#include <QTextStream>
#include <QClipboard>
@ -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,7 +277,8 @@ bool QueryTool::saveSqlTo(const QString &filename)
QFile file(filename);
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream.setCodec("utf-8");
//stream.setCodec("utf-8");
stream.setEncoding(QStringConverter::Utf8);
QString text = ui->queryEdit->toPlainText();
stream << text;

View file

@ -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:

View file

@ -34,7 +34,7 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> 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;

View file

@ -10,7 +10,6 @@ UserConfiguration* UserConfiguration::instance()
UserConfiguration::UserConfiguration()
: m_settings(nullptr)
{
m_settings.setIniCodec("UTF-8");
}
QFont UserConfiguration::codeFont() const

View file

@ -7,14 +7,6 @@
namespace {
class registerMetaTypes {
public:
registerMetaTypes()
{
qRegisterMetaTypeStreamOperators<ConnectionConfig>("ConnectionConfig");
}
} registerMetaTypes_instance;
struct {
SslMode mode;
const char* string;

View file

@ -5,7 +5,7 @@
void FormatToStream(QTextStream &stream, QString format, std::function<void(QTextStream &, QString)> 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<void(QTex
++from;
}
// copy code before the var to the stream
stream << format.midRef(from, match.capturedStart(1) - from);
stream << format.mid(from, match.capturedStart(1) - from);
field_callback(stream, match.captured(2));
from = match.capturedEnd()-1; // -1 because it wants to match one character before or start of line to make sure there is no backslash
}
@ -25,5 +25,5 @@ void FormatToStream(QTextStream &stream, QString format, std::function<void(QTex
// same reason as at the start of the loop
++from;
}
stream << format.midRef(from);
stream << format.mid(from);
}

View file

@ -2,7 +2,7 @@
/**
*/
QString convert(QStringRef in, ConvertToNumericEscape conversion, NumericEscapeFormat format, QString prefix)
QString convert(QStringView in, ConvertToNumericEscape conversion, NumericEscapeFormat format, QString prefix)
{
return "";
return "TODO";
}

View file

@ -86,7 +86,7 @@ void copySelectionToClipboard(const QTableView *view)
if (selectedIndexes.count() > 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);
}

View file

@ -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<int>(strlen(data)) + 1 : 0);
m_paramFormats.push_back(0);
return Param(*this, m_paramValues.size() - 1);
return Param(*this, static_cast<int>(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<int>(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<int>(m_paramTypes.size());
m_paramValues.reserve(n);
for (int i = 0; i < n; ++i) {
if (r[i]) {