2453 Commits

Author SHA1 Message Date
Nyall Dawson
b6b7a7f8c6 Remove delete* methods from QgsTaskManager API
On further consideration allowing external control of task
deletion is a bad idea.
2016-12-05 14:08:11 +10:00
Nyall Dawson
6d4392a0f7 Allow QgsTask subclasses to defined a finished function, which is
called when the task has completed (successfully or otherwise).

This allows for simpler task design when the signal/slot
based approach is not required. Just implement run() with your
heavy lifting, and finished() to do whatever follow up stuff
should happen after the task is complete. finished is always
called from the main thread, so it's safe to do GUI operations
here.

Python based tasks using the simplified QgsTask.fromFunction
approach can now set a on_finished argument to a function
to call when the task is complete.

eg:

def calculate(task):
    # pretend this is some complex maths and stuff we want
    # to run in the background
    return 5*6

def calculation_finished(result, value=None):
    if result == QgsTask.ResultSuccess:
	iface.messageBar().pushMessage(
            'the magic number is {}'.format(value))
    elif result == QgsTask.ResultFail:
        iface.messageBar().pushMessage(
            'couldn\'t work it out, sorry')

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)

Multiple values can also be returned, eg:

def calculate(task):
    return (4, 8, 15)

def calculation_finished(result, count=None, max=None, sum=None):
    # here:
    # count = 4
    # max = 8
    # sum = 15

task = QgsTask.fromFunction('my task', calculate,
		on_finished=calculation_finished)
QgsTaskManager.instance().addTask(task)
2016-12-05 14:08:11 +10:00
Nyall Dawson
252f2e1102 Rename overloaded signal, flip remaining connects to new style 2016-12-05 14:08:11 +10:00
Nyall Dawson
f71c78e14f Rename stopped to terminated for consistency 2016-12-05 14:08:11 +10:00
Nyall Dawson
e01c306edb Simplify reporting completion of tasks
QgsTask subclasses can now return a result (success or fail)
directly from QgsTask::run. If they do so then there's no
need for them to manually call completed() or stopped()
to report their completion.

Alternatively, tasks can also return the ResultPending value
to indicate that the task is still operating and will
manually report its completion by calling completed() or
stopped(). This may be useful for tasks which rely on external
events for completion, eg downloading a file. In this case
Qt slots could be created which are connected to the download
completion or termination and which call completed() or
stopped() to indicate the task has finished operations.
2016-12-05 14:08:11 +10:00
Nyall Dawson
95dbb3a7e3 Add deleteAllTasks to manager 2016-12-05 14:08:11 +10:00
Nyall Dawson
b64025df5c Add python test for task manager 2016-12-05 14:08:11 +10:00
Nyall Dawson
d270b4f9c2 Improvements to task manager ui 2016-12-05 14:08:11 +10:00
Nyall Dawson
55e9d32671 Add handling of dependent layers to task manager
If a task has dependent layers which are about to be removed,
the task will automatically be cancelled
2016-12-05 14:08:11 +10:00
Nyall Dawson
4c0f4ee6f0 Resolve circular dependencies 2016-12-05 14:08:11 +10:00
Nyall Dawson
b065edeed7 Improvements to QgsTaskWrapper 2016-12-05 14:08:11 +10:00
Nyall Dawson
4291904c8d Support for dependent tasks
Cancelling a task on which others depend leads to all these other
tasks getting cancelled as well.
2016-12-05 14:08:11 +10:00
Nyall Dawson
dcecf4476f Add support for placing queued tasks on hold 2016-12-05 14:08:10 +10:00
Nyall Dawson
cf5eeb758b API cleanups 2016-12-05 14:08:10 +10:00
Nyall Dawson
5d4689294d Add simple python method QgsTask.fromFunction for creation of tasks
from a function without having to create a QgsTask subclass
2016-12-05 14:08:10 +10:00
Nyall Dawson
e29dd79432 Api + test cleanups 2016-12-05 14:08:10 +10:00
Nyall Dawson
6021d7806e Make QgsTaskManager handle threading of tasks 2016-12-05 14:08:10 +10:00
Nyall Dawson
ebae15f23a Framework for task manager
Adds new classes:
- QgsTask. An interface for long-running background tasks
- QgsTaskManager. Handles groups of tasks - also available as a global
instance for tracking application wide tasks
- QgsTaskManagerWidget. A list view for showing active tasks and their
progress, and for cancelling them

A new dock widget has been added with a task manager widget showing
global tasks
2016-12-05 14:08:10 +10:00
nirvn
56c5534455 [symblogy] migrate heatmap renderer color ramp widget 2016-12-03 13:40:27 +07:00
Nyall Dawson
3a789e5f14 Merge pull request #3825 from nyalldawson/legend_count
QgsVectorLayer::featureCount( QgsSymbol* symbol ) to featureCount( const QString& legendKey )
2016-12-02 16:35:20 +10:00
Mathieu Pellerin
eb85e3fcfa [raster] migrate singleband pseudo-color renderer color ramp widget (#3817) 2016-12-02 12:48:45 +07:00
Nyall Dawson
7de1cc2f13 Removed unused QgsLayerTreeModelLegendNode::SymbolLegacyRuleKeyRole 2016-12-02 13:55:41 +10:00
Nyall Dawson
6d0203d612 Change QgsVectorLayer::featureCount( QgsSymbol* symbol ) to instead
use a legend key string

Avoids crashes due to symbol pointer lifetime issues
2016-12-02 13:55:41 +10:00
Nyall Dawson
a17facf6cb Merge pull request #3816 from nyalldawson/processing_datetime
[processing][FEATURE] New unified basic stats algorithm
2016-12-01 20:37:15 +10:00
Mathieu Pellerin
ae75e45d80 [symbology] migrate graduated renderer color ramp widget (#3815) 2016-11-30 16:47:23 +07:00
nirvn
deb18c40db color ramp button widget for gradiant fill and categorized renderer 2016-11-30 11:02:05 +07:00
nirvn
7181cf25e8 [color ramp] implement invert() function 2016-11-30 09:57:24 +07:00
Nyall Dawson
a927d9743f Allow QgsStringStatisticalSummary to calculate mean string length 2016-11-30 12:03:32 +10:00
Nyall Dawson
57f17e31e2 Merge pull request #3808 from nyalldawson/processing_dupe_remove_rings
[processing] Remove duplicate fill holes algorithm
2016-11-30 09:50:57 +10:00
Alessandro Pasotti
61b599ed0e Added histogram values to the bindings 2016-11-29 15:44:34 +01:00
Nyall Dawson
45a52dfacd Rename minimum area paremeter, fix docs for QgsCurvePolygon::removeInteriorRing 2016-11-29 08:43:23 +10:00
Nyall Dawson
57f482e2d9 Add method to QgsGeometry to remove interior rings from a polygon
With an optional area threshold
2016-11-28 12:08:21 +10:00
Matthias Kuhn
7726205dc3 Followup f3482d2: mapThemeStyleOverrides is plural 2016-11-23 15:51:10 +01:00
Nathan
311f482725 Move profiler instance to QgsApplication 2016-11-23 14:03:25 +10:00
nirvn
bc130be6cb [style] improve creation of default style db
Instead of copyign a pre-existing .db shipped with QGIS, create
a new .db and import an .xml file containing our default  symbols.

On the UX front, the main benefit is being able to ship with
pre-defined tags and favorite flags for the default symbols.

On the developer side, it means we get rid of the requirement
to maintain both an .xml and a binary .db in the source tree.
We also say aurevoir to the symbol_xml2db.py script and the
need to update the (obsolete) script every time we add a new
feature to QgsStyle.
2016-11-22 14:46:35 +07:00
nirvn
a958c8a798 [style] add createMemoryDB() to QgsStyle to create temporary db 2016-11-19 16:04:03 +07:00
nirvn
5f3ba72547 [style manager] sort displayed symbols, insure tags are added only once 2016-11-18 14:14:16 +07:00
nirvn
13a0e48a26 [style manager] improve UI
- create a dedicated set of buttons for addition of tags and smartgroups
to make those actions more visible as well as getting rid of th need to
select a tag/smartgroup to create those (turns out to be quite confusing
for newcomers)
- move UI elements around, regroup {add,remove,edit} symbol buttons to
harmonize with other parts of QGIS; the elements' placement feels much
more natural now
2016-11-18 10:15:40 +07:00
nirvn
a8a05ba751 [symbology] add padding value for symbol/coloramp preview 2016-11-17 11:43:53 +07:00
Nyall Dawson
e624518e00 Merge pull request #3755 from nirvn/style_manager_upgrade
[FEATURE] Style management re-work and upgrade
2016-11-17 12:40:52 +10:00
Nyall Dawson
1da400a99d Rename enum values for consistency 2016-11-17 09:04:19 +10:00
Nyall Dawson
5c3aea33b8 Allow filtering QgsMapLayerComboBox by data provider 2016-11-17 09:04:19 +10:00
Nyall Dawson
9ee7873572 Allow showing additional items in QgsMapLayerComboBox
These may represent additional layers such as layers which
are not included in the map layer registry, or paths to
layers which have not yet been loaded into QGIS.
2016-11-17 09:04:19 +10:00
Nyall Dawson
ec49341f85 Allow showing CRS in QgsMapLayerComboBox 2016-11-17 09:04:19 +10:00
Nyall Dawson
959f97f682 Allow not set choice in QgsMapLayerComboBox 2016-11-17 09:04:19 +10:00
Nyall Dawson
60bbd09339 Avoid double-evaluating postgres default values 2016-11-16 14:19:24 +01:00
Nyall Dawson
b5864cd432 [FEATURE] Improve handling of defaults (inc provider default clauses,
literal defaults, and qgis expression defaults) and automatically
handle unique value constraints on layers

Add a new method QgsVectorLayerUtils::createFeature which returns
a new feature which includes all relevant defaults. Any fields
with unique value constraints will be guaranteed to have a value
which is unique for the field.

Currently only in use by the split feature tool.

Sponsored by Canton of Zug and the QGEP project
2016-11-16 14:19:24 +01:00
Nyall Dawson
747097d43d New method QgsVectorLayerUtils::createUniqueValue
Returns a new unique attribute value for a layer. For numeric
fields this is the max attribute value + 1, for strings we
attempt to create a unique value by append _1, _2, etc to either
a specified 'seed' value, or failing that to the end of the
value of that field from the first feature in the layer.
2016-11-16 14:19:24 +01:00
Nyall Dawson
4682eaf6eb Add QgsVectorLayer::uniqueStringsMatching() to retrieve
a list of unique strings matching a substring for a field
2016-11-16 14:19:24 +01:00
Nyall Dawson
3242321aa9 [FEATURE] Add method to get list of unique strings matching
a substring from a vector data provider

Base implementation iterates through all features, but
providers can override with optimised versions. Native
implementations for postgres, spatialite and OGR included.
2016-11-16 14:19:24 +01:00