-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gui] Introduce EditBasketDialog, load info from the selected basket …
…in BasketManager; for changing the selected basket's dataset, disable datasets that already have a basket for the selected basket's topic (since we shouldn't have 2 baskets for the same topic in the same dataset)
- Loading branch information
1 parent
8a746d7
commit 91e423f
Showing
5 changed files
with
253 additions
and
5 deletions.
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
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,92 @@ | ||
""" | ||
/*************************************************************************** | ||
------------------- | ||
begin : 20.09.2024 | ||
git sha : :%H$ | ||
copyright : (C) 2024 by Germán Carrillo | ||
email : german at opengis ch | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
from qgis.PyQt.QtCore import Qt | ||
from qgis.PyQt.QtWidgets import QDialog, QWidget | ||
|
||
from QgisModelBaker.libs.modelbaker.dbconnector.db_connector import DBConnector | ||
from QgisModelBaker.utils import gui_utils | ||
|
||
DIALOG_UI = gui_utils.get_ui_class("edit_basket.ui") | ||
|
||
|
||
class EditBasketDialog(QDialog, DIALOG_UI): | ||
def __init__( | ||
self, parent: QWidget, db_connector: DBConnector, basket_configuration: dict | ||
) -> None: | ||
QDialog.__init__(self, parent) | ||
self.setupUi(self) | ||
self.db_connector = db_connector | ||
|
||
self.buttonBox.accepted.connect(self._accept) | ||
|
||
self._basket_info = basket_configuration | ||
self.txtTopic.setText(self._basket_info["topic"]) | ||
self.txtBidOidType.setText(self._basket_info["bid_domain"]) | ||
self.txtBidValue.setText(self._basket_info["bid_value"]) | ||
self.txtAttachmentKey.setText(self._basket_info["attachment_key"]) | ||
|
||
# Fill filtered datasets | ||
for t_id, dataset_data in self._get_filtered_datasets().items(): | ||
self.cboDatasets.addItem(dataset_data["datasetname"], t_id) | ||
|
||
if not dataset_data["enabled"]: | ||
model = self.cboDatasets.model() | ||
item = model.item(self.cboDatasets.count() - 1) | ||
item.setFlags(item.flags() & ~Qt.ItemIsEnabled) # Disable mirror item | ||
|
||
# Select the current basket's dataset | ||
self.cboDatasets.setCurrentIndex( | ||
self.cboDatasets.findData(self._basket_info["dataset_t_id"]) | ||
) | ||
|
||
def _get_filtered_datasets(self) -> dict: | ||
# Returns datasets info, marking as disabled those that | ||
# already have a basket for the editing basket's topic. | ||
filtered_datasets = {} # {dataset_id1: {'datasetname': name, 'enabled': True}} | ||
|
||
# Obtain DB datasets | ||
for record in self.db_connector.get_datasets_info(): | ||
filtered_datasets[record["t_id"]] = { | ||
"datasetname": record["datasetname"], | ||
"enabled": True, | ||
} | ||
|
||
# Obtain DB baskets info | ||
baskets = self.db_connector.get_baskets_info() | ||
|
||
# Filter baskets belonging to the editing basket's topic. | ||
# Exclude the dataset of the basket being edited (it should | ||
# be enabled to allow selection in the comboBox). | ||
for basket in baskets: | ||
if ( | ||
basket["topic"] == self._basket_info["topic"] | ||
and basket["basket_t_id"] != self._basket_info["basket_t_id"] | ||
): | ||
# Mark their corresponding datasets as disabled | ||
filtered_datasets[basket["dataset_t_id"]]["enabled"] = False | ||
|
||
return filtered_datasets | ||
|
||
def _accept(self): | ||
self._save_edited_basket() | ||
self.close() | ||
|
||
def _save_edited_basket(self): | ||
# Save basket attributes | ||
return |
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,125 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>EditBasket</class> | ||
<widget class="QDialog" name="EditBasket"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>482</width> | ||
<height>259</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Edit Basket</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="toolTip"> | ||
<string>Disabled datasets already have a basket for this topic</string> | ||
</property> | ||
<property name="text"> | ||
<string>Dataset</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QComboBox" name="cboDatasets"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Topic</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QLineEdit" name="txtTopic"> | ||
<property name="readOnly"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="text"> | ||
<string>BID (OID Type)</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QLineEdit" name="txtBidOidType"> | ||
<property name="readOnly"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QLabel" name="label_4"> | ||
<property name="text"> | ||
<string>BID Value</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1"> | ||
<widget class="QLineEdit" name="txtBidValue"/> | ||
</item> | ||
<item row="4" column="0"> | ||
<widget class="QLabel" name="label_5"> | ||
<property name="text"> | ||
<string>Attachment key</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="4" column="1"> | ||
<widget class="QLineEdit" name="txtAttachmentKey"/> | ||
</item> | ||
<item row="5" column="1"> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>EditBasket</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>EditBasket</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |