[education/rkward] rkward: Port away from more Qt5 deprecated functions

Thomas Friedrichsmeier null at kde.org
Mon May 23 21:31:16 BST 2022


Git commit 5eb8650d82a7c7df30502d53b544301ecfb077b6 by Thomas Friedrichsmeier.
Committed on 23/05/2022 at 20:30.
Pushed by tfry into branch 'master'.

Port away from more Qt5 deprecated functions

M  +6    -1    rkward/dialogs/rkloadlibsdialog.cpp
M  +9    -2    rkward/misc/rkfindbar.cpp
M  +1    -1    rkward/misc/rkxmlguipreviewarea.cpp
M  +1    -1    rkward/plugin/rkcomponentmap.cpp
M  +3    -4    rkward/plugin/rkvarslot.cpp
M  +16   -4    rkward/windows/rkhtmlwindow.cpp

https://invent.kde.org/education/rkward/commit/5eb8650d82a7c7df30502d53b544301ecfb077b6

diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 25ea9ca2..f60e5449 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -633,7 +633,12 @@ InstallPackagesWidget::InstallPackagesWidget (RKLoadLibsDialog *dialog) : RKLoad
 	packages_view->setRootIsDecorated (false);
 	packages_view->setIndentation (0);
 	packages_view->setMinimumHeight (packages_view->sizeHintForRow (0) * 15);	// force a decent height
-	packages_view->setMinimumWidth(packages_view->fontMetrics ().width("This is to force a sensible min width for the packages view (empty on construction)")*2);
+	QString dummy("This is to force a sensible min width for the packages view (empty on construction)");
+#if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
+	packages_view->setMinimumWidth(packages_view->fontMetrics().horizontalAdvance(dummy)*2);
+#else
+	packages_view->setMinimumWidth(packages_view->fontMetrics().width(dummy)*2);
+#endif
 	vbox->addWidget (packages_view);
 
 	QLabel *label = new QLabel (i18n ("Show only packages matching:"), this);
diff --git a/rkward/misc/rkfindbar.cpp b/rkward/misc/rkfindbar.cpp
index d25c1edf..4e1a116e 100644
--- a/rkward/misc/rkfindbar.cpp
+++ b/rkward/misc/rkfindbar.cpp
@@ -36,8 +36,15 @@ RKFindBar::RKFindBar (QWidget* parent, bool custom) : QWidget (parent) {
 	slayout->setContentsMargins (0, 0, 0, 0);
 	slayout->setSpacing (0);
 	term_edit = new KHistoryComboBox (this);
-	term_edit->setMaximumWidth (fontMetrics ().width ("This is quite a long search term by any standard, indeed"));
-	term_edit->setMinimumWidth (fontMetrics ().width ("A short search term"));
+	QString dummylong("This is quite a long search term by any standard, indeed");
+	QString dummyshort("A short search term");
+#if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
+	term_edit->setMaximumWidth(fontMetrics().horizontalAdvance(dummylong));
+	term_edit->setMinimumWidth(fontMetrics().horizontalAdvance(dummyshort));
+#else
+	term_edit->setMaximumWidth(fontMetrics().width(dummylong));
+	term_edit->setMinimumWidth(fontMetrics().width(dummyshort));
+#endif
 	connect (term_edit, &KHistoryComboBox::editTextChanged, this, &RKFindBar::searchChanged);
 	connect (term_edit, static_cast<void (KHistoryComboBox::*)(const QString&)>(&KHistoryComboBox::returnPressed), this, &RKFindBar::forward);
 	regular_palette = term_edit->palette ();
diff --git a/rkward/misc/rkxmlguipreviewarea.cpp b/rkward/misc/rkxmlguipreviewarea.cpp
index ed3b1ecc..55926cb6 100644
--- a/rkward/misc/rkxmlguipreviewarea.cpp
+++ b/rkward/misc/rkxmlguipreviewarea.cpp
@@ -164,7 +164,7 @@ RKPreviewManager::RKPreviewManager(QObject* parent) : QObject (parent) {
 
 	update_pending = NoUpdatePending;
 	updating = false;
-	id = QString ().sprintf ("%p", this).remove ('%');
+	id = "0x" + QString::number((quint64) (quintptr) this, 16);
 }
 
 RKPreviewManager::~RKPreviewManager () {
diff --git a/rkward/plugin/rkcomponentmap.cpp b/rkward/plugin/rkcomponentmap.cpp
index 96d70e2a..b88d8f4a 100644
--- a/rkward/plugin/rkcomponentmap.cpp
+++ b/rkward/plugin/rkcomponentmap.cpp
@@ -98,7 +98,7 @@ void RKComponentGUIXML::resolveComponentLabelsAndSortMenu (Menu *menu, const QSt
 				resolveComponentLabelsAndSortMenu (static_cast<Menu*> (entry), menu_path.isEmpty () ? entry->label : menu_path + '\t' + entry->label);
 			}
 		}
-		qSort (group->entries.begin (), group->entries.end (), compareMenuEntries);
+		std::sort(group->entries.begin(), group->entries.end(), compareMenuEntries);
 	}
 }
 
diff --git a/rkward/plugin/rkvarslot.cpp b/rkward/plugin/rkvarslot.cpp
index 517d91af..cd6d6460 100644
--- a/rkward/plugin/rkvarslot.cpp
+++ b/rkward/plugin/rkvarslot.cpp
@@ -88,9 +88,8 @@ RKVarSlot::RKVarSlot (const QDomElement &element, RKComponent *parent_component,
 		list->header ()->hide ();
 		QTreeWidgetItem dummy (list);
 		dummy.setText (0, "Tg");
-		int top, left, bottom, right;
-		list->getContentsMargins (&left, &top, &right, &bottom);
-		list->setFixedHeight (list->visualItemRect (&dummy).height () + 2*list->visualItemRect (&dummy).top () + top + bottom);
+		QMargins margins = list->contentsMargins();
+		list->setFixedHeight(list->visualItemRect(&dummy).height() + 2*list->visualItemRect(&dummy).top() + margins.top() + margins.bottom());
 		list->header ()->setStretchLastSection (true);
 		list->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
 		list->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
@@ -209,7 +208,7 @@ void RKVarSlot::addOrRemove (bool add) {
 		for (int i = 0; i < removed.size (); ++i) {
 			removed_rows.append (removed[i].row ());
 		}
-		qSort (removed_rows);
+		std::sort(removed_rows.begin(), removed_rows.end());
 		if (!multi && removed_rows.isEmpty ()) removed_rows.append (0);
 		for (int i = removed_rows.size () - 1; i >= 0; --i) {
 			available->removeAt (removed_rows[i]);
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index d26d59b7..8bd6b755 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -362,10 +362,22 @@ RKHTMLWindow::RKHTMLWindow (QWidget *parent, WindowMode mode) : RKMDIWindow (par
 	connect (page, &QWebPage::downloadRequested, [this](const QNetworkRequest &request) { page->downloadUrl (request.url ()); });
 #else
 	connect (page->profile (), &QWebEngineProfile::downloadRequested, this, [this](QWebEngineDownloadItem* item) {
-		QString path = QFileDialog::getSaveFileName (this, i18n ("Save as"), item->path ());
-		if (path.isEmpty ()) return;
-		item->setPath (path);
-		item->accept ();
+		QString defpath;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
+		QString defpath = QDir(item->downloadDirectory()).absoluteFilePath(downloadFileName());
+#else
+		defpath = item->path();
+#endif
+		QString path = QFileDialog::getSaveFileName(this, i18n("Save as"), defpath);
+		if (path.isEmpty()) return;
+#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
+		QFileInfo fi(path);
+		item->setDownloadDirectory(fi.absoluteDir());
+		item->setDownloadFileName(fi.filename());
+#else
+		item->setPath(path);
+#endif
+		item->accept();
 	});
 #endif
 	connect (page, &RKWebPage::printRequested, this, &RKHTMLWindow::slotPrint);


More information about the rkward-tracker mailing list