QtHelp: changed the code to not use deprecated methods anymore. eric7

Thu, 10 Jun 2021 19:32:22 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 10 Jun 2021 19:32:22 +0200
branch
eric7
changeset 8421
cd4eee7f1d28
parent 8420
ff89f8bac0a5
child 8422
bb5da74c1b3f

QtHelp: changed the code to not use deprecated methods anymore.

eric7/WebBrowser/QtHelp/HelpIndexWidget.py file | annotate | diff | comparison | revisions
eric7/WebBrowser/QtHelp/HelpTopicDialog.py file | annotate | diff | comparison | revisions
eric7/WebBrowser/QtHelp/HelpTopicDialog.ui file | annotate | diff | comparison | revisions
eric7/WebBrowser/QtHelp/QtHelpDocumentationDialog.py file | annotate | diff | comparison | revisions
eric7/WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
--- a/eric7/WebBrowser/QtHelp/HelpIndexWidget.py	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/QtHelp/HelpIndexWidget.py	Thu Jun 10 19:32:22 2021 +0200
@@ -8,6 +8,7 @@
 """
 
 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QEvent
+from PyQt6.QtHelp import QHelpLink
 from PyQt6.QtWidgets import (
     QWidget, QVBoxLayout, QLabel, QLineEdit, QMenu, QDialog, QApplication
 )
@@ -34,8 +35,10 @@
         """
         Constructor
         
-        @param engine reference to the help engine (QHelpEngine)
-        @param parent reference to the parent widget (QWidget)
+        @param engine reference to the help engine
+        @type QHelpEngine
+        @param parent reference to the parent widget
+        @type QWidget
         """
         super().__init__(parent)
         
@@ -62,9 +65,8 @@
             self.__disableSearchEdit)
         self.__engine.indexModel().indexCreated.connect(
             self.__enableSearchEdit)
-        # TODO: change code to use documentActivated and documentsActivated
-        self.__index.linkActivated.connect(self.__linkActivated)
-        self.__index.linksActivated.connect(self.__linksActivated)
+        self.__index.documentActivated.connect(self.__documentActivated)
+        self.__index.documentsActivated.connect(self.__documentsActivated)
         self.__index.customContextMenuRequested.connect(
             self.__showContextMenu)
         self.__searchEdit.returnPressed.connect(
@@ -72,12 +74,13 @@
         self.__layout.addWidget(self.__index)
     
     @pyqtSlot(QUrl, str)
-    def __linkActivated(self, url, keyword, modifiers=None):
+    def __documentActivated(self, document, keyword, modifiers=None):
         """
         Private slot to handle the activation of a keyword entry.
         
-        @param url URL of the selected entry
-        @type QUrl
+        @param document reference to a data structure containing the
+            document info
+        @type QHelpLink
         @param keyword keyword for the URL
         @type str
         @param modifiers keyboard modifiers
@@ -85,65 +88,62 @@
         """
         if modifiers is None:
             modifiers = QApplication.keyboardModifiers()
-        if not url.isEmpty() and url.isValid():
-            if (
-                modifiers & (
-                    Qt.KeyboardModifier.ControlModifier |
-                    Qt.KeyboardModifier.ShiftModifier
-                ) == (
-                    Qt.KeyboardModifier.ControlModifier |
-                    Qt.KeyboardModifier.ShiftModifier
-                )
+        if not document.url.isEmpty() and document.url.isValid():
+            if modifiers & (
+                Qt.KeyboardModifier.ControlModifier |
+                Qt.KeyboardModifier.ControlModifier
             ):
-                self.newBackgroundTab.emit(url)
+                self.newBackgroundTab.emit(document.url)
             elif modifiers & Qt.KeyboardModifier.ControlModifier:
-                self.newTab.emit(url)
+                self.newTab.emit(document.url)
             elif modifiers & Qt.KeyboardModifier.ShiftModifier:
-                self.newWindow.emit(url)
+                self.newWindow.emit(document.url)
             else:
-                self.openUrl.emit(url)
+                self.openUrl.emit(document.url)
     
-    def __linksActivated(self, links, keyword):
+    def __documentsActivated(self, documents, keyword):
         """
-        Private slot to handle the activation of an entry with multiple links.
+        Private slot to handle the activation of an entry with multiple help
+        documents.
         
-        @param links dictionary containing the links
-        @type dict of key:str and value:QUrl
+        @param documents list of help document link data structures
+        @type list of QHelpLink
         @param keyword keyword for the entry
         @type str
         """
         modifiers = QApplication.keyboardModifiers()
-        url = (
-            QUrl(links[list(links.keys())[0]])
-            if len(links) == 1 else
-            self.__selectLink(links, keyword)
+        document = (
+            documents[0]
+            if len(documents) == 1 else
+            self.__selectDocument(documents, keyword)
         )
-        self.__linkActivated(url, keyword, modifiers)
+        self.__documentActivated(document, keyword, modifiers)
     
-    def __selectLink(self, links, keyword):
+    def __selectDocument(self, documents, keyword):
         """
         Private method to give the user a chance to select among the
-        returned links.
+        given documents.
         
-        @param links dictionary of document title and URL to select from
-        @type dictionary of str (key) and QUrl (value)
-        @param keyword keyword for the link set
+        @param documents list of help document link data structures
+        @type list of QHelpLink
+        @param keyword keyword for the documents
         @type str
-        @return selected link
-        @rtype QUrl
+        @return selected document
+        @rtype QHelpLink
         """
-        link = QUrl()
+        document = QHelpLink()
         from .HelpTopicDialog import HelpTopicDialog
-        dlg = HelpTopicDialog(self, keyword, links)
+        dlg = HelpTopicDialog(self, keyword, documents)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            link = dlg.link()
-        return link
+            document = dlg.document()
+        return document
     
     def __filterIndices(self, indexFilter):
         """
         Private slot to filter the indexes according to the given filter.
         
-        @param indexFilter filter to be used (string)
+        @param indexFilter filter to be used
+        @type str
         """
         if '*' in indexFilter:
             self.__index.filterIndices(indexFilter, indexFilter)
@@ -167,7 +167,8 @@
         """
         Protected method handling focus in events.
         
-        @param evt reference to the focus event object (QFocusEvent)
+        @param evt reference to the focus event object
+        @type QFocusEvent
         """
         if evt.reason() != Qt.FocusReason.MouseFocusReason:
             self.__searchEdit.selectAll()
@@ -177,9 +178,12 @@
         """
         Public method called to filter the event queue.
         
-        @param watched the QObject being watched (QObject)
-        @param event the event that occurred (QEvent)
-        @return flag indicating whether the event was handled (boolean)
+        @param watched the QObject being watched
+        @type QObject
+        @param event the event that occurred
+        @type QEvent
+        @return flag indicating whether the event was handled
+        @rtype bool
         """
         if (
             self.__searchEdit and watched == self.__searchEdit and
@@ -205,7 +209,8 @@
         """
         Private slot showing the context menu.
         
-        @param pos position to show the menu at (QPoint)
+        @param pos position to show the menu at
+        @type QPoint
         """
         idx = self.__index.indexAt(pos)
         if idx.isValid():
--- a/eric7/WebBrowser/QtHelp/HelpTopicDialog.py	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/QtHelp/HelpTopicDialog.py	Thu Jun 10 19:32:22 2021 +0200
@@ -7,8 +7,9 @@
 Module implementing a dialog to select a help topic to display.
 """
 
+from PyQt6.QtCore import Qt
+from PyQt6.QtHelp import QHelpLink
 from PyQt6.QtWidgets import QDialog
-from PyQt6.QtCore import QUrl
 
 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog
 
@@ -17,14 +18,16 @@
     """
     Class implementing a dialog to select a help topic to display.
     """
-    def __init__(self, parent, keyword, links):
+    def __init__(self, parent, keyword, documents):
         """
         Constructor
         
-        @param parent reference to the parent widget (QWidget)
-        @param keyword keyword for the link set (string)
-        @param links dictionary with help topic as key (string) and
-            URL as value (QUrl)
+        @param parent reference to the parent widget
+        @type QWidget
+        @param keyword keyword for the link set
+        @type str
+        @param documents list of help document link data structures
+        @type list of QHelpLink
         """
         super().__init__(parent)
         self.setupUi(self)
@@ -32,27 +35,27 @@
         self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:")
                            .format(keyword))
         
-        self.__links = links
-        for topic in sorted(self.__links):
-            self.topicsList.addItem(topic)
+        for document in documents:
+            itm = self.topicsList.addItem(document.title)
+            itm.setData(Qt.ItemDataRole.UserRole, document.url)
         if self.topicsList.count() > 0:
             self.topicsList.setCurrentRow(0)
         self.topicsList.setFocus()
         
         self.topicsList.itemActivated.connect(self.accept)
     
-    def link(self):
+    def document(self):
         """
-        Public method to the link of the selected topic.
+        Public method to retrieve the selected help topic.
         
-        @return URL of the selected topic (QUrl)
+        @return help document link for the selected help topic
+        @rtype QHelpLink
         """
+        document = QHelpLink()
+        
         itm = self.topicsList.currentItem()
-        if itm is None:
-            return QUrl()
+        if itm is not None:
+            document.title = itm.text()
+            document.url = itm.data(Qt.ItemDataRole.UserRole)
         
-        topic = itm.text()
-        if topic == "" or topic not in self.__links:
-            return QUrl()
-        
-        return self.__links[topic]
+        return document
--- a/eric7/WebBrowser/QtHelp/HelpTopicDialog.ui	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/QtHelp/HelpTopicDialog.ui	Thu Jun 10 19:32:22 2021 +0200
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>HelpTopicDialog</class>
- <widget class="QDialog" name="HelpTopicDialog" >
-  <property name="geometry" >
+ <widget class="QDialog" name="HelpTopicDialog">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
@@ -9,29 +10,36 @@
     <height>300</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Select Help Topic</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout" >
+  <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QLabel" name="label" >
-     <property name="text" >
+    <widget class="QLabel" name="label">
+     <property name="text">
       <string>&amp;Topics:</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>topicsList</cstring>
      </property>
     </widget>
    </item>
    <item>
-    <widget class="QListWidget" name="topicsList" />
+    <widget class="QListWidget" name="topicsList">
+     <property name="alternatingRowColors">
+      <bool>true</bool>
+     </property>
+     <property name="sortingEnabled">
+      <bool>true</bool>
+     </property>
+    </widget>
    </item>
    <item>
-    <widget class="QDialogButtonBox" name="buttonBox" >
-     <property name="orientation" >
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="standardButtons" >
+     <property name="standardButtons">
       <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
      </property>
     </widget>
@@ -50,11 +58,11 @@
    <receiver>HelpTopicDialog</receiver>
    <slot>accept()</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>248</x>
      <y>254</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>157</x>
      <y>274</y>
     </hint>
@@ -66,11 +74,11 @@
    <receiver>HelpTopicDialog</receiver>
    <slot>reject()</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>316</x>
      <y>260</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>286</x>
      <y>274</y>
     </hint>
--- a/eric7/WebBrowser/QtHelp/QtHelpDocumentationDialog.py	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/QtHelp/QtHelpDocumentationDialog.py	Thu Jun 10 19:32:22 2021 +0200
@@ -261,6 +261,7 @@
     ## Filters Tab
     ##################################################################
     
+    # TODO: change this to use the new QHelpFilterSettingsWidget class
     def __initFiltersTab(self):
         """
         Private method to initialize the filters tab.
@@ -295,10 +296,9 @@
             if filterName not in self.__filterMap:
                 self.__filterMap[filterName] = filterData
         
-        # TODO: change code to use QHelpFilterEngine and QHelpFilterData
         self.filtersList.addItems(sorted(self.__filterMap.keys()))
-        for attr in helpFilterEngine.filterData():
-            QTreeWidgetItem(self.attributesList, [attr])
+        for component in helpFilterEngine.availableComponents():
+            QTreeWidgetItem(self.attributesList, [component])
         self.attributesList.sortItems(0, Qt.SortOrder.AscendingOrder)
         
         if selectedFiltersText or currentFilterText or selectedAttributesText:
--- a/eric7/WebBrowser/WebBrowserWindow.py	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/WebBrowserWindow.py	Thu Jun 10 19:32:22 2021 +0200
@@ -197,6 +197,7 @@
             self.__helpEngine = QHelpEngine(
                 WebBrowserWindow.getQtHelpCollectionFileName(),
                 self)
+            self.__helpEngine.setUsesFilterEngine(True)
             self.__removeOldDocumentation()
             self.__helpEngine.warning.connect(self.__warning)
         else:
@@ -2310,7 +2311,7 @@
             filtertb.addWidget(QLabel(self.tr("Filtered by: ")))
             filtertb.addWidget(self.filterCombo)
             self.__helpEngine.setupFinished.connect(self.__setupFilterCombo)
-            self.filterCombo.activated[int].connect(
+            self.filterCombo.currentTextChanged.connect(
                 self.__filterQtHelpDocumentation)
             self.__setupFilterCombo()
             self.__toolbars["filter"] = (filtertb.windowTitle(), filtertb)
@@ -3436,26 +3437,23 @@
         Private slot to setup the filter combo box.
         """
         if WebBrowserWindow._useQtHelp:
-            curFilter = self.filterCombo.currentText()
-            if not curFilter:
-                curFilter = self.__helpEngine.currentFilter()
+            activeFilter = self.filterCombo.currentText()
+            if not activeFilter:
+                activeFilter = self.__helpEngine.filterEngine().activeFilter()
             self.filterCombo.clear()
-            self.filterCombo.addItems(self.__helpEngine.customFilters())
-            idx = self.filterCombo.findText(curFilter)
-            if idx < 0:
-                idx = 0
-            self.filterCombo.setCurrentIndex(idx)
-        
-    def __filterQtHelpDocumentation(self, index):
+            self.filterCombo.addItems(sorted(
+                self.__helpEngine.filterEngine().filters()))
+            self.filterCombo.setCurrentText(activeFilter)
+        
+    def __filterQtHelpDocumentation(self, activeFilter):
         """
         Private slot to filter the QtHelp documentation.
         
-        @param index index of the selected entry
-        @type int
-        """
-        customFilter = self.filterCombo.itemText(index)
+        @param activeFilter current text of the filter combobox
+        @type str
+        """
         if self.__helpEngine:
-            self.__helpEngine.setCurrentFilter(customFilter)
+            self.__helpEngine.filterEngine().setActiveFilter(activeFilter)
         
     def __manageQtHelpDocumentation(self):
         """

eric ide

mercurial