-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ux] Use a combobox to edit sslmode setting
- Loading branch information
1 parent
99f1059
commit ecebef0
Showing
5 changed files
with
75 additions
and
1 deletion.
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
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) |