659 Commits

Author SHA1 Message Date
Matthias Kuhn
d7b85c69f8
Merge pull request #7016 from m-kuhn/featureSourceEmpty
QgsFeatureSource::empty() method
2018-06-26 13:01:08 +02:00
Etienne Trimaille
6eeaca5570 return the default style first in the list 2018-06-22 09:23:47 +10:00
Mathieu Pellerin
0a325f1eda
Avoid signalling repaint / data signals when a setSubsetString doesn't actually change (#7217)
Behavior across providers harmonized & test added.
2018-06-11 15:52:23 +07:00
Matthias Kuhn
b568d6be55
Add optimized version of QgsPostgresProvider::empty() 2018-06-04 08:59:28 +02:00
Even Rouault
a9a8fbdb17
[cleanup] use for range based loop 2018-06-01 23:09:32 +02:00
Even Rouault
cc25727a18
[Postgres provider] Speed up feature insertion when pkid column is not set (fixes #18976)
When inserting features whose attribute column corresponding to the pkid
is empty, and tat this pkid column has a default value using a sequence,
then we can remove it from the INSERT statement completely, which save us
from doing a SELECT nextval(...) for each row. On the provided test case
of that ticket, on a debug build, this cuts down the insertion time from 5 minutes
to 1 minute 10s.
2018-06-01 22:31:09 +02:00
Nyall Dawson
1c615c15cc More documentation compliance
Use Qt style "returns .." tense instead of "return ..", and lock
this in with a documentation compliance unit test
2018-05-25 15:09:00 +10:00
Nyall Dawson
44630b47ed Add QgsDataProvider::ProviderOptions struct to constructors
for data providers

Allows a way to pass generic settings to providers, e.g.
passing a datum transform context for use in provider's
constructors.
2018-05-25 11:40:57 +10:00
Martin Dobias
0f5ea535cb Implement project storage for PostgreSQL + tests of the storage 2018-04-07 12:58:02 +02:00
Juergen E. Fischer
fcacb0db7c doxygen fixes 2018-04-02 22:48:40 +02:00
Nyall Dawson
7dd5cafc00 [postgres] Automatically populate layer metadata
Not much is available to automatically populate, but we can
set the abstract to match the table comment, the crs, and datatype.
2018-03-15 10:43:04 +11:00
Nyall Dawson
b920799a29 Fix leak in postgres provider loadStyle 2018-02-26 18:40:03 +11:00
Nyall Dawson
8ce519d2ad Fix memory leak in QgsPostgresProvider::createEmptyLayer 2018-02-26 18:40:03 +11:00
Nyall Dawson
fb3e1c398d Fix intermittently failing postgres provider test
Provider can crash if features do not have enough attributes
set to match fields in layer.
2018-02-26 18:40:03 +11:00
Nyall Dawson
84d2443b0a Try to fix postgres provider handling of missing attributes 2018-02-17 19:10:04 +11:00
Nyall Dawson
0e68a3e775 Rollback rejection of features with too many attributes
Turns out editable joins rely on this situation. Instead change
the providers to warn on this occurance, and make the memory
provider alone truncate the extra attributes (since it doesn't
have an external backend or disk based format which natively
applies this truncation)
2018-02-17 19:10:04 +11:00
Nyall Dawson
0a5d48612c Add provider test to ensure providers reject adding features
with geometry type mismatch
2018-02-17 19:10:04 +11:00
Nyall Dawson
7187ae3544 Ensure ogr, postgis and memory providers reject features
with too many attributes
2018-02-17 19:10:04 +11:00
Denis Rouzaud
bfe35c26ea [postgres] use pg_type rather than information_schema.domain_constraints to retrieve domain
otherwise there is no warranty to retrieve the correct constraint as its name is not unique
2018-02-11 17:29:18 -04:00
Denis Rouzaud
498e55186c [postgres] fix domain not in public schema
fix #18053
correctly set enumeration widget in case the domain is not in public schema
also fixes an issue if two domain with the same are present in two schemas
2018-02-10 15:26:29 -04:00
Harrissou Sant-anna
3f801b5d16 Switch SpatiaLite and PostgreSQL place in Datasource
Manager dialog
Moves up SpatiaLite tab near GeoPackage's as they are both simple file databases and their dialog look alike.
2018-01-23 12:35:44 +11:00
Martin Dobias
6a4b8b4762 Fix retrieval of 4D geometries (XYZM) from postgres (fixes #17814) 2018-01-17 15:38:27 +01:00
Nyall Dawson
a15b54d997 Swap missing 0->nullptr and add missing overrides 2017-12-12 21:14:58 +11:00
Alessandro Pasotti
9f56878d88 [bugfix] Add some more logic to get the schema name if empty 2017-11-22 17:22:14 +01:00
Alessandro Pasotti
23dfb1de57 [bugfix] Browser panel D&D a layer onto a postgresql connection tree node icon fails without notice
Fixes #17518 by defaulting to "public" if no schema is given
2017-11-22 13:02:15 +01:00
Nyall Dawson
75885d70d5 Rename various WKT/WKB/GeoJSON/GML methods for consistency
and consistent capitalisation
2017-11-15 20:51:05 +10:00
Alessandro Pasotti
fe5653101a [bugfix][postgresql] Fix crashes on featureCount()
Fixes #17388

Needs backporting
2017-11-10 16:32:50 +01:00
Matthias Kuhn
b18c891dfc [postgres] Fix default value check if evaluated server side 2017-11-09 01:19:35 +01:00
Matthias Kuhn
3b0b82cbe5 [postgres] Distinguish empty and NULL values 2017-10-28 23:14:24 +02:00
Juergen E. Fischer
25b0421752 follow up f243b8448e2 2017-10-21 17:55:28 +02:00
Juergen E. Fischer
f243b8448e postgres: add support for partitioned tables (implements #17302) 2017-10-21 17:39:18 +02:00
Juergen E. Fischer
e6f5236527 postgres provider: queries have an unknown relation type 2017-10-21 17:39:18 +02:00
Matthias Kuhn
d4635d042d Merge pull request #5317 from pblottiere/bugfix_style
[bugfix] Fixes #17234 save/load styles from Postgres when a service file is used
2017-10-16 10:27:10 +02:00
Blottiere Paul
924ce81790 Fixes #17234 save/load styles from Postgres when a service file is used 2017-10-06 17:16:24 +01:00
Nyall Dawson
04a9cd9211 Add more consistency to doxygen formatting 2017-10-06 08:19:00 +10:00
Nyall Dawson
92af1dacaf Replace default constructors/destructors with = default 2017-10-01 06:52:14 +10:00
Nyall Dawson
8c3939e756 More efficient use of QStrings
- use .isEmpty() instead of == QLatin1String( "" ) to check for
empty strings
- use .clear() instead of = QLatin1String( "" ) to empty a string
- remove unnecessary QString initializations
2017-09-28 05:25:51 +10:00
Nyall Dawson
a87d352bd7 Run clang-tidy modernize-use-default-member-init to move member
initialization to headers (c++11 style)
2017-09-27 05:02:34 +10:00
Nyall Dawson
31c1ae1c6a Add missing QStringLiterals 2017-09-25 17:12:03 +10:00
Nyall Dawson
f952e6a647 Misc clazy fixes 2017-09-25 17:11:46 +10:00
Vincent Mora
02e3916bf5 [FEATURE] layer refresh and trigger actions on provider notification
[needs-docs]

In vector layer properties (only usefull for postgres datasources)

**in the rendering tab**

A "Refresh layer on notification" checkbox has been added to refresh layer
on provider notification.

For a postgres datasource, if a `NOTIFY qgis;` command is issued by one of the database clients,
a refresh of the layer will occur.

If the "Only if message is" checkbox is checked, the notification will trigger the refresh only
if the message contend is the one specified, e.g. if the user enters
"refresh" in the box right next to the "Only if message is" checkbox,
then a `NOTIFY qgis, 'refresh';` command in the datatabase will trigger
a layer refresh, but `NOTIFY qgis;` or `NOTIFY qgis, 'something else';`
won't.

**in the actions tab**

A column "On notification" has been added, the action editor widget
a has text field "Execute if notification message matches" to
specify a filter for notification from the provider. The filter is a
Perl-type regex.

Note that, as opposed to the "layer refresh" that

Exemple:
  - QGIS side "Execute if notification message matches" `^trigger my action`
  - Postgres side: `NOTIFY qgis, 'trigger my action'` will trigger the action
  - Postgres side: `NOTIFY qgis, 'trigger my action some additional data'` will trigger the action
  - Postgres side: `NOTIFY qgis, 'do not trigger my action some additional data'` will NOT trigger the action

Please note that if the `^`, which means "starts with",  in `^trigger my action` had been ommited,
the last notification would have triggered the action because the
notification message contains the `trigger my action`

A new qgis variable `notification_message` is available for use in
actions, it holds the contend of the notification message. To continue
with the previous exemple, if the action is of python type with the code:

```python
print('[% @notification_message %]')
```

The three notifictions above will result in two printed lines
```
trigger my action
trigger my action some additional data
```

User Warning:

For postgres providers, if the "Refresh layer on notification" is checked, or if one layer action has
"On notification" specified, a new connection to the database is made to
listen to postgres notifications. This olds even if transaction groups
are enabled at the project level.

Note that once the notification mechanism is started in a QGIS
session, it will not stop, even if there is no more need for it (Refresh
layer on notification" unchecked and no "On notification" in any
action). Consequently the connection listening to notification will
remain open.

IMPLEMENTATION DETAILS:

A notify signal has been added to the abstract QgsVectorDataProvider
along with a setListening function that enables/disble the notification
mechanism.

For the moment only the postgres provider implements the notification.

QgsAction has a notificationMessage member function that holds the regex
to match to trigger action

QgsActionManager becomes a QObject and is doing the filtering and execute actions on
notifications.

The notification notion extends beyond SRGBD servers (postgres and oracle at
least have the notify) and the "watch file" in the delimitedtext
provider could also benefit from this interface.

For the postgres provider a thread is created with a second connection
to the database. This thread is responsible for listening postgres
notifications.

It would be nice to avoid the creation of one listening chanel per
provider in the case transaction groups are enabled.

Please note that when listening starts (a thread and connection is
created in the postgres provider) it cannot be stopped by removing the
connected actions or unchecking the refresh check box. Indeed, since we
don't know who needs the signals, we dont't want to stop the service.

The service will not restart in the next qgis session though.

If this behavior is not deemed appropriate, we could use
```
int QObject::receivers ( const char * signal ) const
```
and have QgsDataProvider::setListening return a bool to tell the caller
if the signal has actually been closed.
2017-09-22 12:51:51 +02:00
Vincent Mora
f63c302420 [FEATURE] Add undo and redo on transaction groups (#4765)
* [FEATURE] adds undo/redo for transaction groups

[needs-docs] the undo/redo now works with transcation groups. Just check
that there is no restriction in the transaction groups doc concerning
undo.

related to #14799

The undo/redo is implemented using SAVEPOINT.

The QgsTransaction interface has been enlarged to allow savepoints
creation and management. The savepoint is destroyed on
rollbackToSavepoint to have the same behavior has the sql ROLLBACK TO
SAVEPPOINT.

To avoid the creation of a savepoint for each feature modified in bulk
editing (e.g. paste, field calculator) the logic is a bit complicated: the
savepoint is created on QgsVectorLayer::editCommandStarted and the first
actual undo command (QgsVectorLayerUndoPassthroughCommand) is
responsible for the re-creation of the savepoint in case of undo-redo.
Since the behavior must be different in case edition doesn't take place
inside an edit command, a member function has been added to
QgsVectorLayer to expose the mEditCommandActive state.

Another (commented) tricky bit is the modification of the database
structure on add/delete attributes. On undo, the attribute is removed
before the rollback to savepoint, i.e. there is a useless ALTER TABLE
issued to restore the structure just before restoring it with the
ROLLBACK TO SAVEPOINT. This is necessary to make the provider
aware of the change of structure. It could be nicer/cleaner to have a way
to reload providers metadata.

The editPaste function has also been modified to use addFeatures instead of
addFeature (plural/singular), this is at the expense of an additional "cpy"
of the clipboard in memory, but it should improve perf with postgis provider.

* fixup operator aliases
2017-09-15 14:55:43 +02:00
Nyall Dawson
15f9241109 Add a bit more structure to provider source select ordering 2017-09-13 05:47:20 +10:00
Nyall Dawson
357f998e44 Remove redundant virtual keyword from signatures with override 2017-09-11 21:27:02 +10:00
Nyall Dawson
ba64e3e533 Remove redundant initializations
Fixes when a member is initialized both in the header and
source to the same initial value

(via clang-tidy modernize-use-default-member-init fixit)
2017-09-11 17:09:35 +10:00
Blottiere Paul
8a17a608e1 Trust is now a project option instead of a global option 2017-09-06 15:22:38 +01:00
Blottiere Paul
b55c134926 Do not check primary key unicity on views when trustProject option is activated 2017-09-06 14:46:37 +01:00
Blottiere Paul
384e85ca77 Add option on layer to read extent from xml in case of data source without metadata 2017-09-06 14:46:37 +01:00
Blottiere Paul
5b5dc9545d Add an enum for postgres relation kind 2017-09-06 14:46:37 +01:00
Alessandro Pasotti
d47fdbc79c Implement sourceSelectProviders() for all providers 2017-09-04 15:28:52 +02:00