Skip to content
Permalink
Browse files

Add universal last-resort signal QgsGui::optionsChanged()

This signal is emitted whenever the application options have been changed.

This signal is a "blanket" signal, and will be emitted whenever the options dialog
has been accepted regardless of whether or not individual settings are changed.
It is designed as a "last resort" fallback only, allowing widgets to respond
to possible settings changes.
  • Loading branch information
nyalldawson committed Oct 5, 2020
1 parent 4723642 commit 527e8850ef92362ba61178d69da092fd9683e288
@@ -28,9 +28,9 @@
from .console_sci import ShellScintilla
from .console_output import ShellOutputScintilla
from .console_editor import EditorTabWidget
from .console_settings import ConsoleOptionsFactory, settingsWatcher
from .console_settings import ConsoleOptionsFactory
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.gui import QgsFilterLineEdit, QgsHelp, QgsDockWidget
from qgis.gui import QgsFilterLineEdit, QgsHelp, QgsDockWidget, QgsGui
from functools import partial

import sys
@@ -89,7 +89,7 @@ def __init__(self, parent=None):
# self.setAllowedAreas(Qt.BottomDockWidgetArea)

self.console = PythonConsoleWidget(self)
settingsWatcher.settingsChanged.connect(self.console.updateSettings)
QgsGui.instance().optionsChanged.connect(self.console.updateSettings)
self.setWidget(self.console)
self.setFocusProxy(self.console)

@@ -19,7 +19,7 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from qgis.PyQt.QtCore import QCoreApplication, QUrl, QObject, pyqtSignal
from qgis.PyQt.QtCore import QCoreApplication, QUrl
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QTableWidgetItem, QHBoxLayout
from qgis.PyQt.QtGui import QIcon, QDesktopServices

@@ -30,13 +30,6 @@
from .ui_console_settings import Ui_SettingsDialogPythonConsole


class SettingsWatcher(QObject):
settingsChanged = pyqtSignal()


settingsWatcher = SettingsWatcher()


class ConsoleOptionsFactory(QgsOptionsWidgetFactory):

def __init__(self):
@@ -162,7 +155,6 @@ def accept(self):
)
return
self.saveSettings()
settingsWatcher.settingsChanged.emit()
self.listPath = []
QDialog.accept(self)

@@ -167,6 +167,21 @@ Returns the screen at the given global ``point`` (pixel).
%End



signals:

void optionsChanged();
%Docstring
This signal is emitted whenever the application options have been changed.

This signal is a "blanket" signal, and will be emitted whenever the options dialog
has been accepted regardless of whether or not individual settings are changed.
It is designed as a "last resort" fallback only, allowing widgets to respond
to possible settings changes.

.. versionadded:: 3.16
%End

private:
QgsGui( const QgsGui &other );
};
@@ -1840,6 +1840,8 @@ void QgsOptions::saveOptions()
{
widget->apply();
}

QgsGui::instance()->emitOptionsChanged();
}

void QgsOptions::rejectOptions()
@@ -316,3 +316,10 @@ bool QgsGui::pythonMacroAllowed( void ( *lambda )(), QgsMessageBar *messageBar )
}
return false;
}

///@cond PRIVATE
void QgsGui::emitOptionsChanged()
{
emit optionsChanged();
}
///@endcond
@@ -211,6 +211,24 @@ class GUI_EXPORT QgsGui : public QObject
*/
static bool pythonMacroAllowed( void ( *lambda )() = nullptr, QgsMessageBar *messageBar = nullptr ) SIP_SKIP;

///@cond PRIVATE
void emitOptionsChanged() SIP_SKIP;
///@endcond

signals:

/**
* This signal is emitted whenever the application options have been changed.
*
* This signal is a "blanket" signal, and will be emitted whenever the options dialog
* has been accepted regardless of whether or not individual settings are changed.
* It is designed as a "last resort" fallback only, allowing widgets to respond
* to possible settings changes.
*
* \since QGIS 3.16
*/
void optionsChanged();

private:

QgsGui();

0 comments on commit 527e885

Please sign in to comment.
You can’t perform that action at this time.