From 53a7ee1981784b713f553f015c7638dce9d8d4a8 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sun, 12 Sep 2021 12:18:46 +0800 Subject: [PATCH] fix: port away from deprecated Qt APIs --- caesium.cpp | 33 ++++++++++++++++++--------------- updater.cpp | 5 +++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/caesium.cpp b/caesium.cpp index 3af5bcc..b015fba 100644 --- a/caesium.cpp +++ b/caesium.cpp @@ -1,6 +1,7 @@ /******************************************************************************* # # Copyright (C) 2010-2013 Matteo Paonessa +# 2021 Gary Wang # # This file is part of the Caesium distribution. # @@ -19,6 +20,7 @@ # Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. # # Author: Matteo Paonessa +# Gary Wang # # ******************************************************************************/ @@ -53,7 +55,7 @@ #include #include -QTime t; +QElapsedTimer t; int error_count = 0, iteration_count = 0, skipped_count; int current_index = -1; double scale_factor = 1.0; @@ -751,14 +753,14 @@ void Caesium::on_listTreeWidget_itemSelectionChanged() void Caesium::on_actionSave_List_As_triggered() { - QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."), QString::null, tr("Caesium List (*.clf)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."), QString(), tr("Caesium List (*.clf)")); Caesium::saveList(fileName); opened_list = fileName; } void Caesium::on_actionOpen_List_triggered() { - QString listName = QFileDialog::getOpenFileName(this, tr("Open a list file..."), QString::null, tr("Caesium List (*.clf)")); + QString listName = QFileDialog::getOpenFileName(this, tr("Open a list file..."), QString(), tr("Caesium List (*.clf)")); Caesium::openList(listName); } @@ -970,11 +972,11 @@ void Caesium::updateUI(int i, int newSize, QString ratio) chopped_ratio.chop(1); if (chopped_ratio.toInt() > 0) { - ui->listTreeWidget->topLevelItem(i - 1)->setTextColor(3, QColor::fromRgb(255, 0, 0, 255)); + ui->listTreeWidget->topLevelItem(i - 1)->setForeground(3, QColor::fromRgb(255, 0, 0, 255)); } else { - ui->listTreeWidget->topLevelItem(i - 1)->setTextColor(3, QColor::fromRgb(0, 0, 0, 255)); + ui->listTreeWidget->topLevelItem(i - 1)->setForeground(3, QColor::fromRgb(0, 0, 0, 255)); } } @@ -1192,7 +1194,7 @@ void Caesium::openList() ui->listTreeWidget->clear(); QTextStream stream(&list); QString line = stream.readLine(0); - while (line != QString::null) + while (!line.isNull()) { QStringList splittedLine = line.split("|"); if (splittedLine.count() != 7) @@ -1217,11 +1219,11 @@ void Caesium::lstSave() QTextStream stream(&file); if (ui->rememberDirectoryCheckBox->isChecked()) { - stream << "1|" << ui->outputLineEdit->text() << endl; + stream << "1|" << ui->outputLineEdit->text() << Qt::endl; } else { - stream << "0|" << ui->outputLineEdit->text() << endl; + stream << "0|" << ui->outputLineEdit->text() << Qt::endl; } } QString tempFolder = QDir::tempPath(); @@ -1356,13 +1358,14 @@ void Caesium::adjustPreviewView() { if (!deleting) { - img_ratio = (double) imageLabel1->pixmap()->width() / imageLabel1->pixmap()->height(); + QPixmap imgLabel1Pixmap = imageLabel1->pixmap(Qt::ReturnByValue); + img_ratio = (double) imgLabel1Pixmap.width() / imgLabel1Pixmap.height(); if (ui->listTreeWidget->selectedItems().at(0)->text(6) == "") { if (ui->methodComboBox->currentIndex() == 0) { - ui->widthSpinBox->setValue(imageLabel1->pixmap()->width()); - ui->heightSpinBox->setValue(imageLabel1->pixmap()->height()); + ui->widthSpinBox->setValue(imgLabel1Pixmap.width()); + ui->heightSpinBox->setValue(imgLabel1Pixmap.height()); } else { @@ -1379,8 +1382,8 @@ void Caesium::adjustPreviewView() else { QList wh = resolutionToInt(ui->listTreeWidget->selectedItems().at(0)->text(6)); - ui->widthSpinBox->setValue(100 * wh.at(0) / imageLabel1->pixmap()->width()); - ui->heightSpinBox->setValue(100 * wh.at(1) / imageLabel1->pixmap()->height()); + ui->widthSpinBox->setValue(100 * wh.at(0) / imgLabel1Pixmap.width()); + ui->heightSpinBox->setValue(100 * wh.at(1) / imgLabel1Pixmap.height()); } } if(settings.value("Preferences/imageview").value() == "fit") @@ -1698,7 +1701,7 @@ void Caesium::saveList(QString path) << ui->listTreeWidget->topLevelItem(i)->text(5) + "|" << ui->listTreeWidget->topLevelItem(i)->text(6) + "|" << ui->listTreeWidget->topLevelItem(i)->text(7) + "|" - << endl; + << Qt::endl; } } } @@ -1711,7 +1714,7 @@ void Caesium::openList(QString path) ui->listTreeWidget->clear(); QTextStream stream(&list); QString line = stream.readLine(0); - while (line != QString::null) + while (!line.isNull()) { QStringList splittedLine = line.split("|"); QTreeWidgetItem *item = new QTreeWidgetItem(splittedLine, 0); diff --git a/updater.cpp b/updater.cpp index cad7c68..11a0de1 100644 --- a/updater.cpp +++ b/updater.cpp @@ -1,6 +1,7 @@ /******************************************************************************* # # Copyright (C) 2010-2013 Matteo Paonessa +# 2021 Gary Wang # # This file is part of the Caesium distribution. # @@ -19,6 +20,7 @@ # Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. # # Author: Matteo Paonessa +# Gary Wang # # ******************************************************************************/ @@ -196,8 +198,7 @@ void Updater::closeEvent(QCloseEvent *event) { if (downFinished) { - QProcess *process; - process->startDetached(QDir::tempPath() + "/" + fileName); + QProcess::startDetached(QDir::tempPath() + "/" + fileName, {}); u_parent->close(); } else if (start_pressed)