Skip to content

Commit

Permalink
Merge pull request #56 from myarjunar/button-behavior
Browse files Browse the repository at this point in the history
disable bearing distance tool when no beacons available
  • Loading branch information
mazano authored Jan 9, 2018
2 parents 6acfed3 + 490afa0 commit f407ba2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
18 changes: 16 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import database
from constants import *
from datetime import datetime
from utilities import validate_plugin_actions


class RequiredLayer:
Expand Down Expand Up @@ -347,6 +348,7 @@ def manage_beacons(self):
return
self.refresh_layers()
BeaconManager(self.iface, self.database, self.required_layers)
validate_plugin_actions(self, self.database)
self.iface.mapCanvas().refresh()

def manage_parcels(self):
Expand All @@ -360,6 +362,7 @@ def manage_parcels(self):
return
self.refresh_layers()
ParcelManager(self.iface, self.database, self.required_layers)
validate_plugin_actions(self, self.database)
self.iface.mapCanvas().refresh()

def manage_bearing_distance(self):
Expand All @@ -372,8 +375,18 @@ def manage_bearing_distance(self):
self.set_database_connection()
if self.database is None:
return
self.refresh_layers()
BearDistManager(self.iface, self.database, self.required_layers)

result = validate_plugin_actions(self, self.database)
if not result:
QMessageBox.warning(
None,
"SML Surveyor",
("No Beacons available in the table. "
"Please use Beacon Manager tool to create a Beacon."))
else:
self.refresh_layers()
BearDistManager(self.iface, self.database, self.required_layers)

self.iface.mapCanvas().refresh()

def manage_database_connection(self):
Expand All @@ -384,6 +397,7 @@ def manage_database_connection(self):
crs = database_manager.get_current_crs()
if connection:
self.set_database_connection(connection=connection, crs=crs)
validate_plugin_actions(self, self.database)


class DatabaseManager():
Expand Down
25 changes: 25 additions & 0 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ def get_ui_class(ui_file):
)
return uic.loadUiType(ui_file_path, from_imports=True)[0]

def validate_plugin_actions(toolbar, database):
"""Check DB schema for actions availability. eg: Manage bearing and
distance action needs Beacon to be created first.
:param database: Database instance
:type database: database.Manager
:param toolbar: plugin toolbar
:type toolbar: SMLSurveyor
:return: Query result
:rtype: tuple
"""
query = "select * from survey limit 1;"
try:
result = database.query(query=query)
except Exception as e:
raise Exception(
'Backend database query failed!\nError raised: %s.' % (str(e),))
if result:
toolbar.bearing_distance_action.setEnabled(True)
else:
toolbar.bearing_distance_action.setEnabled(False)
return result


class ExtendedComboBox(QComboBox):
"""Extended class of QComboBox so we can perform a filtering of items.
Expand Down

0 comments on commit f407ba2

Please sign in to comment.