Skip to content

Commit

Permalink
Merge pull request #600 from opengisch/QF-4546-filter_visible_layers_…
Browse files Browse the repository at this point in the history
…for_packaging_offline_project

Filters visible layers for packaging offline project
  • Loading branch information
suricactus authored Aug 27, 2024
2 parents c62b447 + 8ef04b0 commit 561f4cf
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 49 deletions.
28 changes: 27 additions & 1 deletion qfieldsync/gui/layers_config_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def __init__(self, project, use_cloud_actions, layer_sources, parent=None):
)
message_bus.messaged.connect(self._on_message_bus_messaged_wrapper)

self.showVisibleLayersOnlyCheckbox.stateChanged.connect(self.reloadProject)
self.textFilterBox.textChanged.connect(self.reloadProject)

self.reloadProject()

def get_available_actions(self, layer_source):
Expand Down Expand Up @@ -128,7 +131,30 @@ def reloadProject(self):

self.layersTable.setRowCount(0)
self.layersTable.setSortingEnabled(False)
for layer_source in self.layer_sources:

# Get filtered layers
show_visible_only = self.showVisibleLayersOnlyCheckbox.isChecked()
filter_text = self.textFilterBox.text().lower()

layers = []
if show_visible_only:
for layer_source in self.layer_sources:
if (
QgsProject.instance()
.layerTreeRoot()
.findLayer(layer_source.layer.id())
.isVisible()
):
layers.append(layer_source)
else:
layers = self.layer_sources

for layer_source in layers:
layer_name = layer_source.layer.name().lower()

if filter_text and filter_text not in layer_name:
continue

count = self.layersTable.rowCount()
self.layersTable.insertRow(count)
item = QTableWidgetItem(layer_source.layer.name())
Expand Down
107 changes: 59 additions & 48 deletions qfieldsync/ui/layers_config_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,23 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="2">
<widget class="QToolButton" name="multipleToggleButton">
<property name="toolTip">
<string>Toggle layers</string>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="unsupportedLayersLabel">
<property name="visible">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>../resources/visibility.svg</normaloff>../resources/visibility.svg</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="autoRaise">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Layers</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<item row="1" column="0" colspan="2">
<widget class="QTableWidget" name="layersTable">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
Expand All @@ -83,29 +59,64 @@
</column>
<column>
<property name="text">
<string></string>
<string/>
</property>
</column>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="unsupportedLayersLabel">
<property name="visible">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsFilterLineEdit" name="textFilterBox">
<property name="placeholderText">
<string>Filter layers...</string>
</property>
<property name="showSearchIcon">
<bool>true</bool>
</property>
<property name="qgisRelation" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showVisibleLayersOnlyCheckbox">
<property name="text">
<string>Show Visible Layers Only</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="multipleToggleButton">
<property name="toolTip">
<string>Toggle layers</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>../resources/visibility.svg</normaloff>../resources/visibility.svg</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 561f4cf

Please sign in to comment.