mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Allow adding custom highlight widget to custom pages in option
This commit is contained in:
parent
fe31c28257
commit
8d55cadeb7
@ -38,12 +38,24 @@ If an empty string is returned by this method the default QGIS options
|
||||
help will be retrieved.
|
||||
%End
|
||||
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void apply() = 0;
|
||||
%Docstring
|
||||
Called to permanently apply the settings shown in the options page (e.g. save them to
|
||||
QgsSettings objects). This is usually called when the options dialog is accepted.
|
||||
%End
|
||||
|
||||
protected:
|
||||
|
||||
void registerHighlightWidget( QgsOptionsDialogHighlightWidget *highlightWidget /Transfer/ );
|
||||
%Docstring
|
||||
Register a highlight widget to be used to search and highlight text in
|
||||
options dialogs. This can be used to provide a custom implementation of
|
||||
:py:class:`QgsOptionsDialogHighlightWidget`.
|
||||
%End
|
||||
|
||||
};
|
||||
|
@ -47,7 +47,8 @@ from qgis.PyQt.QtGui import (QIcon,
|
||||
|
||||
from qgis.gui import (QgsDoubleSpinBox,
|
||||
QgsSpinBox,
|
||||
QgsOptionsPageWidget)
|
||||
QgsOptionsPageWidget,
|
||||
QgsOptionsDialogHighlightWidget)
|
||||
from qgis.core import NULL, QgsApplication, QgsSettings
|
||||
from qgis.utils import OverrideCursor
|
||||
|
||||
@ -68,13 +69,15 @@ class ConfigOptionsPage(QgsOptionsPageWidget):
|
||||
|
||||
def __init__(self, parent):
|
||||
super(ConfigOptionsPage, self).__init__(parent)
|
||||
self.config_widget = ConfigDialog()
|
||||
self.config_widget = ConfigDialog(False)
|
||||
layout = QHBoxLayout()
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setMargin(0)
|
||||
self.setLayout(layout)
|
||||
layout.addWidget(self.config_widget)
|
||||
self.setObjectName('processingOptions')
|
||||
self.highlightWidget = ProcessingTreeHighlight(self.config_widget)
|
||||
self.registerHighlightWidget(self.highlightWidget)
|
||||
|
||||
def apply(self):
|
||||
self.config_widget.accept()
|
||||
@ -83,9 +86,24 @@ class ConfigOptionsPage(QgsOptionsPageWidget):
|
||||
return 'processing/index.html'
|
||||
|
||||
|
||||
class ProcessingTreeHighlight(QgsOptionsDialogHighlightWidget):
|
||||
def __init__(self, config_dialog):
|
||||
super(ProcessingTreeHighlight, self).__init__(config_dialog.tree)
|
||||
self.config_dialog = config_dialog
|
||||
|
||||
def highlightText(self, text):
|
||||
return self.config_dialog.textChanged(text)
|
||||
|
||||
def searchText(self, text):
|
||||
return self.config_dialog.textChanged(text)
|
||||
|
||||
def reset(self):
|
||||
self.config_dialog.textChanged('')
|
||||
|
||||
|
||||
class ConfigDialog(BASE, WIDGET):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, showSearch=True):
|
||||
super(ConfigDialog, self).__init__(None)
|
||||
self.setupUi(self)
|
||||
|
||||
@ -95,29 +113,36 @@ class ConfigDialog(BASE, WIDGET):
|
||||
self.groupIcon.addPixmap(self.style().standardPixmap(
|
||||
QStyle.SP_DirOpenIcon), QIcon.Normal, QIcon.On)
|
||||
|
||||
if hasattr(self.searchBox, 'setPlaceholderText'):
|
||||
self.searchBox.setPlaceholderText(self.tr('Search...'))
|
||||
|
||||
self.model = QStandardItemModel()
|
||||
self.tree.setModel(self.model)
|
||||
|
||||
self.delegate = SettingDelegate()
|
||||
self.tree.setItemDelegateForColumn(1, self.delegate)
|
||||
|
||||
self.searchBox.textChanged.connect(self.textChanged)
|
||||
if showSearch:
|
||||
if hasattr(self.searchBox, 'setPlaceholderText'):
|
||||
self.searchBox.setPlaceholderText(self.tr('Search...'))
|
||||
self.searchBox.textChanged.connect(self.textChanged)
|
||||
else:
|
||||
self.searchBox.hide()
|
||||
|
||||
self.fillTree()
|
||||
|
||||
self.saveMenus = False
|
||||
self.tree.expanded.connect(self.itemExpanded)
|
||||
|
||||
def textChanged(self):
|
||||
text = str(self.searchBox.text().lower())
|
||||
def textChanged(self, text=None):
|
||||
if text is not None:
|
||||
text = str(text.lower())
|
||||
else:
|
||||
text = str(self.searchBox.text().lower())
|
||||
self._filterItem(self.model.invisibleRootItem(), text)
|
||||
if text:
|
||||
self.tree.expandAll()
|
||||
return True
|
||||
else:
|
||||
self.tree.collapseAll()
|
||||
return False
|
||||
|
||||
def _filterItem(self, item, text):
|
||||
if item.hasChildren():
|
||||
|
@ -256,7 +256,25 @@ void QgsOptionsDialogBase::registerTextSearchWidgets()
|
||||
{
|
||||
Q_FOREACH ( QWidget *w, mOptStackedWidget->widget( i )->findChildren<QWidget *>() )
|
||||
{
|
||||
QgsOptionsDialogHighlightWidget *shw = QgsOptionsDialogHighlightWidget::createWidget( w );
|
||||
|
||||
// get custom highlight widget in user added pages
|
||||
QMap<QWidget *, QgsOptionsDialogHighlightWidget *> customHighlightWidgets = QMap<QWidget *, QgsOptionsDialogHighlightWidget *>();
|
||||
QgsOptionsPageWidget *opw = qobject_cast<QgsOptionsPageWidget *>( mOptStackedWidget->widget( i ) );
|
||||
if ( opw )
|
||||
{
|
||||
customHighlightWidgets = opw->registeredHighlightWidgets();
|
||||
}
|
||||
QgsOptionsDialogHighlightWidget *shw = nullptr;
|
||||
// take custom if exists
|
||||
if ( customHighlightWidgets.contains( w ) )
|
||||
{
|
||||
shw = customHighlightWidgets.value( w );
|
||||
}
|
||||
// try to construct one otherwise
|
||||
if ( !shw || !shw->isValid() )
|
||||
{
|
||||
shw = QgsOptionsDialogHighlightWidget::createWidget( w );
|
||||
}
|
||||
if ( shw && shw->isValid() )
|
||||
{
|
||||
QgsDebugMsgLevel( QString( "Registering: %1" ).arg( w->objectName() ), 4 );
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <QListWidgetItem>
|
||||
#include "qgis_gui.h"
|
||||
#include "qgis.h"
|
||||
#include "qgsoptionsdialoghighlightwidget.h"
|
||||
|
||||
/**
|
||||
* \ingroup gui
|
||||
@ -51,6 +52,14 @@ class GUI_EXPORT QgsOptionsPageWidget : public QWidget
|
||||
*/
|
||||
virtual QString helpKey() const { return QString(); }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the registered highlight widgets used to search and highlight text in
|
||||
* options dialogs.
|
||||
*/
|
||||
QMap<QWidget *, QgsOptionsDialogHighlightWidget *> registeredHighlightWidgets() {return mHighlighWidgets;} SIP_SKIP
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
@ -59,6 +68,23 @@ class GUI_EXPORT QgsOptionsPageWidget : public QWidget
|
||||
*/
|
||||
virtual void apply() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Register a highlight widget to be used to search and highlight text in
|
||||
* options dialogs. This can be used to provide a custom implementation of
|
||||
* QgsOptionsDialogHighlightWidget.
|
||||
*/
|
||||
void registerHighlightWidget( QgsOptionsDialogHighlightWidget *highlightWidget SIP_TRANSFER )
|
||||
{
|
||||
mHighlighWidgets.insert( highlightWidget->widget(), highlightWidget );
|
||||
}
|
||||
|
||||
private:
|
||||
QMap<QWidget *, QgsOptionsDialogHighlightWidget *> mHighlighWidgets = QMap<QWidget *, QgsOptionsDialogHighlightWidget *>();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user