-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ux] Use a combobox to edit sslmode setting #45
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import Enum | ||
|
||
|
||
class SslModeEnum(Enum): | ||
DISABLE = "disable" | ||
ALLOW = "allow" | ||
PREFER = "prefer" | ||
REQUIRE = "require" | ||
VERIFY_CA = "verify-ca" | ||
VERIFY_FULL = "verify-full" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
from qgis.PyQt.QtCore import QAbstractTableModel, QModelIndex, Qt, pyqtSignal | ||
from qgis.PyQt.QtGui import QColorConstants, QFont | ||
|
||
from pg_service_parser.conf.enums import SslModeEnum | ||
from pg_service_parser.conf.service_settings import SERVICE_SETTINGS | ||
|
||
|
||
class ServiceConfigModel(QAbstractTableModel): | ||
KEY_COL = 0 | ||
VALUE_COL = 1 | ||
|
||
SSLMODE_KEY = "sslmode" | ||
|
||
is_dirty_changed = pyqtSignal(bool) # Whether the model gets dirty or not | ||
|
||
def __init__(self, service_name: str, service_config: dict): | ||
|
@@ -85,6 +88,9 @@ def data(self, index, role=Qt.ItemDataRole.DisplayRole): | |
or self.__model_data[key] != self.__original_data[key] | ||
): | ||
return QColorConstants.DarkGreen | ||
elif role == Qt.ItemDataRole.UserRole: | ||
if index.column() == self.VALUE_COL and key == self.SSLMODE_KEY: | ||
return {key: [e.value for e in SslModeEnum]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at it, I guess this list could be created at |
||
|
||
return None | ||
|
||
|
@@ -144,3 +150,11 @@ def invalid_settings(self): | |
:return: List of invalid settings. | ||
""" | ||
return [k for k, v in self.__model_data.items() if v.strip() == ""] | ||
|
||
@staticmethod | ||
def is_sslmode_edit_cell(index): | ||
return ( | ||
index.column() == ServiceConfigModel.VALUE_COL | ||
and isinstance(index.data(Qt.ItemDataRole.UserRole), dict) | ||
and ServiceConfigModel.SSLMODE_KEY in index.data(Qt.ItemDataRole.UserRole) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Adapted from | ||
# https://github.com/xxyzz/WordDumb/blob/097dd6c1651fdc08b472e0bf639aec444b6e14ec/custom_lemmas.py#L398C1-L438C46 | ||
|
||
from qgis.PyQt.QtCore import Qt | ||
from qgis.PyQt.QtWidgets import QComboBox, QStyledItemDelegate | ||
|
||
from pg_service_parser.core.item_models import ServiceConfigModel | ||
|
||
|
||
class ServiceConfigDelegate(QStyledItemDelegate): | ||
def __init__(self, parent): | ||
super().__init__(parent) | ||
|
||
def createEditor(self, parent, option, index): | ||
if ServiceConfigModel.is_sslmode_edit_cell(index): | ||
options = list(index.data(Qt.ItemDataRole.UserRole).values())[0] | ||
combo_box = QComboBox(parent) | ||
if isinstance(options, list): | ||
for value in options: | ||
combo_box.addItem(value, value) | ||
|
||
combo_box.currentIndexChanged.connect(self.commit_and_close_editor) | ||
|
||
return combo_box | ||
|
||
return QStyledItemDelegate.createEditor(self, parent, option, index) | ||
|
||
def commit_and_close_editor(self): | ||
editor = self.sender() | ||
self.commitData.emit(editor) | ||
self.closeEditor.emit(editor) | ||
|
||
def setEditorData(self, editor, index): | ||
if ServiceConfigModel.is_sslmode_edit_cell(index): | ||
value = index.data(Qt.ItemDataRole.DisplayRole) | ||
editor.setCurrentText(value) | ||
else: | ||
QStyledItemDelegate.setEditorData(self, editor, index) | ||
|
||
def setModelData(self, editor, model, index): | ||
if ServiceConfigModel.is_sslmode_edit_cell(index): | ||
value = editor.currentData() | ||
model.setData(index, value, Qt.ItemDataRole.EditRole) | ||
else: | ||
QStyledItemDelegate.setModelData(self, editor, model, index) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also add tooltips for each value here, perhaps as a separate key (e.g.,
"value_tooltips"
) and assign a list of tooltips.Now, this dict is growing as you said, we could perhaps address this in a follow-up PR later (I'll wait for your instructions regarding that).