On Fri, Feb 28, 2020 at 02:35:18PM -0500, Scott Kostyshak wrote:
> Compiling LyX with Qt 5.14.1 gives deprecation warnings, which breaks
> compilation of LyX with -Werror. I'm working on a patch to address
> these. I'm sending this message just to avoid duplication of effort in
> case anyone else comes across these warnings. I'll hopefully finish the
> patch next week.

Attached is a patch that fixes a few warnings. There is one part of the
patch that I don't understand. Fixing these warnings was mechanical so I
don't think I need to understand it, but I'm still curious in case
anyone happens to know. The question is regarding the change below:

                // show all hidden items
                QTreeWidgetItemIterator it(shortcutsTW, 
QTreeWidgetItemIterator::Hidden);
                for (; *it; ++it)
-                       shortcutsTW->setItemHidden(*it, isAlwaysHidden(**it));
+                       (*it)->setHidden(isAlwaysHidden(**it));
                // close all categories
                for (int i = 0; i < shortcutsTW->topLevelItemCount(); ++i)
                        shortcutsTW->collapseItem(shortcutsTW->topLevelItem(i));

"it" is a QTreeWidgetItemIterator. "*it" is a QTreeWidgetItem. I don't
understand what "**it" is, or how it works. Does this mean that somehow
a QTreeWidgetItem::operator* is defined or something like that? 

Scott
From 902ae101ed40c7695eafcff0c8eafda29b88e8db Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Tue, 3 Mar 2020 09:28:20 -0500
Subject: [PATCH] Fix a few deprecation warnings in Qt 5.14.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

These changes fix a few instances of the following type of warning:

  error: ‘void QListWidget::setItemSelected(const QListWidgetItem*, bool)’ is deprecated: Use QListWidgetItem::setSelected() instead [-Werror=deprecated-declarations]

as well as similar warnings for setItemHidden() and
setItemExpanded(). These are just warnings now, but it is planned to
remove the methods for Qt 6:

  https://bugreports.qt.io/browse/QTBUG-73048

I tested that LyX can still be built against Qt 4.8.7 with this
commit. Indeed, these methods have been deprecated for a while (it
is just that QT_DEPRECATED_WARNINGS was only turned on by default
starting with 5.13.0). see, e.g.,

  https://doc.qt.io/archives/qt-4.7/qlistwidget-obsolete.html
---
 src/frontends/qt/BulletsModule.cpp | 2 +-
 src/frontends/qt/GuiBranches.cpp   | 2 +-
 src/frontends/qt/GuiIndices.cpp    | 2 +-
 src/frontends/qt/GuiPrefs.cpp      | 8 ++++----
 src/frontends/qt/GuiRef.cpp        | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/frontends/qt/BulletsModule.cpp b/src/frontends/qt/BulletsModule.cpp
index 5cbca093e8..ef21bd9723 100644
--- a/src/frontends/qt/BulletsModule.cpp
+++ b/src/frontends/qt/BulletsModule.cpp
@@ -159,7 +159,7 @@ void BulletsModule::selectItem(int font, int character, bool select)
 		return;
 
 	QListWidget * lw = static_cast<QListWidget *>(bulletpaneSW->widget(font));
-	lw->setItemSelected(lw->item(character), select);
+	lw->item(character)->setSelected(select);
 }
 
 
diff --git a/src/frontends/qt/GuiBranches.cpp b/src/frontends/qt/GuiBranches.cpp
index ab91587098..b1ef8be307 100644
--- a/src/frontends/qt/GuiBranches.cpp
+++ b/src/frontends/qt/GuiBranches.cpp
@@ -144,7 +144,7 @@ void GuiBranches::updateView()
 		// restore selected branch
 		if (bname == sel_branch) {
 			branchesTW->setCurrentItem(newItem);
-			branchesTW->setItemSelected(newItem, true);
+			newItem->setSelected(true);
 		}
 	}
 	unknownPB->setEnabled(!unknown_branches_.isEmpty());
diff --git a/src/frontends/qt/GuiIndices.cpp b/src/frontends/qt/GuiIndices.cpp
index 7c7a61014a..5e145f56eb 100644
--- a/src/frontends/qt/GuiIndices.cpp
+++ b/src/frontends/qt/GuiIndices.cpp
@@ -146,7 +146,7 @@ void GuiIndices::updateView()
 		// restore selected index
 		if (iname == sel_index) {
 			indicesTW->setCurrentItem(newItem);
-			indicesTW->setItemSelected(newItem, true);
+			newItem->setSelected(true);
 		}
 	}
 	indicesTW->resizeColumnToContents(0);
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 91aa3f67f9..7d269bc104 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -3245,7 +3245,7 @@ void PrefShortcuts::on_searchLE_textEdited()
 		// show all hidden items
 		QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
 		for (; *it; ++it)
-			shortcutsTW->setItemHidden(*it, isAlwaysHidden(**it));
+			(*it)->setHidden(isAlwaysHidden(**it));
 		// close all categories
 		for (int i = 0; i < shortcutsTW->topLevelItemCount(); ++i)
 			shortcutsTW->collapseItem(shortcutsTW->topLevelItem(i));
@@ -3264,8 +3264,8 @@ void PrefShortcuts::on_searchLE_textEdited()
 	// show matched items
 	for (int i = 0; i < matched.size(); ++i)
 		if (!isAlwaysHidden(*matched[i])) {
-			shortcutsTW->setItemHidden(matched[i], false);
-			shortcutsTW->setItemExpanded(matched[i]->parent(), true);
+			matched[i]->setHidden(false);
+			matched[i]->parent()->setExpanded(true);
 		}
 }
 
@@ -3372,7 +3372,7 @@ void PrefShortcuts::shortcutOkPressed()
 	if (item) {
 		user_bind_.bind(&k, func);
 		shortcutsTW->sortItems(0, Qt::AscendingOrder);
-		shortcutsTW->setItemExpanded(item->parent(), true);
+		item->parent()->setExpanded(true);
 		shortcutsTW->setCurrentItem(item);
 		shortcutsTW->scrollToItem(item);
 	} else {
diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp
index 0c6b12d462..6f3a34258e 100644
--- a/src/frontends/qt/GuiRef.cpp
+++ b/src/frontends/qt/GuiRef.cpp
@@ -545,7 +545,7 @@ void GuiRef::redoRefs()
 		while (*it) {
 			if ((*it)->text(0) == textToFind) {
 				refsTW->setCurrentItem(*it);
-				refsTW->setItemSelected(*it, true);
+				(*it)->setSelected(true);
 				//Make sure selected item is visible
 				refsTW->scrollToItem(*it);
 				last_reference_ = textToFind;
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to