-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Filter by resources type using checkbox #29
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ def __init__(self, parent=None, iface=None): | |
self.graphicsViewPreview.setScene(self.graphicsScene) | ||
|
||
# Resources | ||
self.resources = [] | ||
self.resource_model = QStandardItemModel(self.listViewResources) | ||
self.listViewResources.setModel(self.resource_model) | ||
|
||
|
@@ -50,6 +51,16 @@ def __init__(self, parent=None, iface=None): | |
|
||
self.pushButtonDownload.clicked.connect(self.download_resource) | ||
|
||
self.checkBoxGeopackage.stateChanged.connect( | ||
lambda: self.populate_resources(force_update=False) | ||
) | ||
self.checkBoxStyle.stateChanged.connect( | ||
lambda: self.populate_resources(force_update=False) | ||
) | ||
self.checkBoxModel.stateChanged.connect( | ||
lambda: self.populate_resources(force_update=False) | ||
) | ||
|
||
self.reloadToolButton.setIcon( | ||
QIcon(":/images/themes/default/mActionRefresh.svg") | ||
) | ||
|
@@ -60,15 +71,27 @@ def __init__(self, parent=None, iface=None): | |
self.hide_preview() | ||
|
||
def populate_resources(self, force_update=False): | ||
response = get_all_resources(force_update=force_update) | ||
# total = response.get("total") | ||
# previous_url = response.get("previous") | ||
# next_url = response.get("next") | ||
resources = response.get("results", {}) | ||
if force_update or not self.resources: | ||
response = get_all_resources(force_update=force_update) | ||
# total = response.get("total") | ||
# previous_url = response.get("previous") | ||
# next_url = response.get("next") | ||
self.resources = response.get("results", {}) | ||
|
||
geopackage_checked = self.checkBoxGeopackage.isChecked() | ||
style_checked = self.checkBoxStyle.isChecked() | ||
model_checked = self.checkBoxModel.isChecked() | ||
|
||
filtered_resources = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I prefer to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have implemented the |
||
ResourceItem(r) | ||
for r in self.resources | ||
if (geopackage_checked and r["resource_type"] == "Geopackage") | ||
or (style_checked and r["resource_type"] == "Style") | ||
or (model_checked and r["resource_type"] == "Model") | ||
] | ||
|
||
self.resource_model.clear() | ||
for resource in resources: | ||
item = ResourceItem(resource) | ||
for item in filtered_resources: | ||
self.resource_model.appendRow(item) | ||
|
||
@pyqtSlot("QItemSelection", "QItemSelection") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we check in the hub API, there are 5 resource types
It seems the API doesn't return all five resource types. Could you check it? Add the missing 2 check boxes after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the API URL used, it only returns three types of resources.
Is there any other API I can use, or can you direct me to the place where I can find the API's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really documented, but it's from this https://github.com/qgis/QGIS-Django/blob/master/qgis-app/api/urls.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create an issue in that repo to include the other resource type also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qgis/QGIS-Django#280