Skip to content
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

Basket Manager #846

Merged
merged 12 commits into from
Nov 24, 2023
67 changes: 67 additions & 0 deletions QgisModelBaker/gui/basket_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
/***************************************************************************
-------------------
begin : 10.08.2021
git sha : :%H$
copyright : (C) 2021 by Dave Signer
email : david 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.QtWidgets import QDialog, QMessageBox

from QgisModelBaker.gui.panel.basket_panel import BasketPanel
from QgisModelBaker.utils import gui_utils

DIALOG_UI = gui_utils.get_ui_class("basket_manager.ui")


class BasketManagerDialog(QDialog, DIALOG_UI):
def __init__(self, parent=None, db_connector=None, datasetname=None):
QDialog.__init__(self, parent)
self.setupUi(self)

self.datasetname = datasetname
self.db_connector = db_connector

self.buttonBox.accepted.connect(self._accepted)
self.buttonBox.rejected.connect(self._rejected)

# baskets part
self.baskets_panel = BasketPanel(self)
self.baskets_layout.addWidget(self.baskets_panel)

self.baskets_panel.load_basket_config(self.db_connector, self.datasetname)

def _accepted(self):
feedbacks = self.baskets_panel.save_basket_config(
self.db_connector, self.datasetname
)
negative_feedbacks = [
feedback for feedback in feedbacks if feedback[0] is False
]
if negative_feedbacks:
warning_box = QMessageBox(self)
warning_box.setIcon(QMessageBox.Critical)
warning_title = self.tr("Creating baskets failed")
warning_box.setWindowTitle(warning_title)
warning_box.setText(
"{}{}".format(
"\n".join([feedback[1] for feedback in negative_feedbacks]),
"\n(The problem is often an incorrectly formatted BID)",
)
)
warning_box.exec_()
self.close()

def _rejected(self):
self.close()
37 changes: 9 additions & 28 deletions QgisModelBaker/gui/dataset_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from qgis.PyQt.QtWidgets import QDialog, QHeaderView, QMessageBox, QTableView

import QgisModelBaker.libs.modelbaker.utils.db_utils as db_utils
from QgisModelBaker.gui.basket_manager import BasketManagerDialog
from QgisModelBaker.gui.edit_dataset_name import EditDatasetDialog
from QgisModelBaker.gui.panel import db_panel_utils
from QgisModelBaker.libs.modelbaker.db_factory.db_simple_factory import DbSimpleFactory
Expand Down Expand Up @@ -89,7 +90,7 @@ def __init__(self, iface, parent=None, wizard_embedded=False):

self.add_button.clicked.connect(self._add_dataset)
self.edit_button.clicked.connect(self._edit_dataset)
self.create_baskets_button.clicked.connect(self._create_baskets)
self.basket_manager_button.clicked.connect(self._open_basket_manager)
self.dataset_tableview.selectionModel().selectionChanged.connect(
lambda: self._enable_dataset_handling(True)
)
Expand Down Expand Up @@ -126,7 +127,7 @@ def _enable_dataset_handling(self, enable):
self.dataset_tableview.setEnabled(enable)
self.add_button.setEnabled(enable)
self.edit_button.setEnabled(self._valid_selection())
self.create_baskets_button.setEnabled(self._valid_selection())
self.basket_manager_button.setEnabled(self._valid_selection())

def _type_changed(self):
ili_mode = self.type_combo_box.currentData()
Expand Down Expand Up @@ -180,37 +181,17 @@ def _edit_dataset(self):
self._refresh_datasets(self._updated_configuration())
self._jump_to_entry(edit_dataset_dialog.dataset_line_edit.text())

def _create_baskets(self):
def _open_basket_manager(self):
if self._valid_selection():
db_connector = db_utils.get_db_connector(self._updated_configuration())
if db_connector and db_connector.get_basket_handling:
feedbacks = []
for record in db_connector.get_topics_info():
dataset_tid = self.dataset_tableview.selectedIndexes()[0].data(
int(DatasetModel.Roles.TID)
)
status, message = db_connector.create_basket(
dataset_tid, ".".join([record["model"], record["topic"]])
)
feedbacks.append((status, message))

info_box = QMessageBox(self)
info_box.setIcon(
QMessageBox.Warning
if len([feedback for feedback in feedbacks if not feedback[0]])
else QMessageBox.Information
datasetname = self.dataset_tableview.selectedIndexes()[0].data(
int(DatasetModel.Roles.DATASETNAME)
)
info_title = self.tr("Created baskets")
info_box.setWindowTitle(info_title)
info_box.setText(
"{}{}".format(
"\n".join([feedback[1] for feedback in feedbacks]),
"\n\nBe aware that the IDs of the baskets are created as UUIDs. To change that, edit the t_ili2db_basket table manually."
if len([feedback for feedback in feedbacks if feedback[0]])
else "",
)
basket_manager_dialog = BasketManagerDialog(
self, db_connector, datasetname
)
info_box.exec_()
basket_manager_dialog.exec_()

def _jump_to_entry(self, datasetname):
matches = self.dataset_model.match(
Expand Down
Loading
Loading