Skip to content

Commit

Permalink
Add select/deselect all layers button and fix progress bar type error (
Browse files Browse the repository at this point in the history
…#37)

* Add select/deselect all layers button and fix progress bar value error

* Minor improvement
  • Loading branch information
msorvoja authored Jan 19, 2024
1 parent cf88cf8 commit 0704a2b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
21 changes: 18 additions & 3 deletions nlsgpkgloader/nls_geopackage_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
QgsVectorLayer,
)
from qgis.gui import QgsFileWidget
from qgis.PyQt.QtCore import QCoreApplication, QTimer, QTranslator, qVersion
from qgis.PyQt.QtCore import QCoreApplication, Qt, QTimer, QTranslator, qVersion
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QListWidgetItem, QMessageBox
from qgis.utils import iface
Expand Down Expand Up @@ -286,6 +286,10 @@ def run(self):

self.municipalities_dialog.show()

self.municipalities_dialog.selectDeselectAll.clicked.connect(
self.select_deselect_all_layers
)

result = self.municipalities_dialog.exec_()
if result:
self.fileName = self.municipalities_dialog.fileNameEdit.text().strip()
Expand Down Expand Up @@ -660,6 +664,17 @@ def load_layers(self):

return True

def select_deselect_all_layers(self):
if self.municipalities_dialog.selectDeselectAll.isChecked():
for value in self.product_types.values():
items = self.municipalities_dialog.productListWidget.findItems(
value, Qt.MatchExactly
)
if items:
items[0].setSelected(True)
else:
self.municipalities_dialog.productListWidget.clearSelection()

def get_layers(self, root):
layers = []
for node in root.children():
Expand Down Expand Up @@ -800,7 +815,7 @@ def download_one_file(self):

self.download_count += 1
percentage = self.download_count / float(self.total_download_count) * 100.0
self.progress_dialog.progressBar.setValue(percentage)
self.progress_dialog.progressBar.setValue(int(percentage))

if self.download_count == self.total_download_count:
QgsMessageLog.logMessage("done downloading data", "NLSgpkgloader", 0)
Expand Down Expand Up @@ -835,7 +850,7 @@ def create_geopackage(self):
def run_task(self, task):
self.progress_dialog.label.setText(task.description())
task.progressChanged.connect(
lambda: self.progress_dialog.progressBar.setValue(task.progress())
lambda: self.progress_dialog.progressBar.setValue(int(task.progress()))
)
QgsApplication.taskManager().addTask(task)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>329</height>
<width>841</width>
<height>494</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -45,11 +45,34 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Choose layer(s):</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>17</height>
</size>
</property>
<property name="text">
<string>Choose layer(s):</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="selectDeselectAll">
<property name="text">
<string>Select/deselect all</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="productListWidget">
Expand Down

0 comments on commit 0704a2b

Please sign in to comment.