Skip to content

Commit

Permalink
Fix button order in DB styles dialog and add GPKG delete support
Browse files Browse the repository at this point in the history
Fixes #21068

(cherry picked from commit 90a9852)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 20, 2019
1 parent 80ab968 commit 67b5b67
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 111 deletions.
8 changes: 8 additions & 0 deletions src/app/qgsvectorlayerloadstyledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgsvectorlayerproperties.h"
#include "qgsmaplayerstylecategoriesmodel.h"
#include "qgsmessagebar.h"
#include "qgsapplication.h"


QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *layer, QWidget *parent )
Expand All @@ -32,6 +33,13 @@ QgsVectorLayerLoadStyleDialog::QgsVectorLayerLoadStyleDialog( QgsVectorLayer *la
setupUi( this );
setWindowTitle( QStringLiteral( "Database styles manager" ) );

mDeleteButton = mButtonBox->button( QDialogButtonBox::StandardButton::Close );
mDeleteButton->setText( tr( "Delete style" ) );
mDeleteButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDeleteSelected.svg" ) ) );
mLoadButton = mButtonBox->button( QDialogButtonBox::StandardButton::Open );
mLoadButton->setText( tr( "Load style" ) );
mCancelButton = mButtonBox->button( QDialogButtonBox::StandardButton::Cancel );

QgsSettings settings;

QString providerName = mLayer->providerType();
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerloadstyledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class APP_EXPORT QgsVectorLayerLoadStyleDialog : public QDialog, private Ui::Qgs
QString mSelectedStyleId;
QString mSelectedStyleName;
int mSectionLimit = 0;
QPushButton *mDeleteButton = nullptr;
QPushButton *mLoadButton = nullptr;
QPushButton *mCancelButton = nullptr;
};

#endif //QGSLOADFILEFROMDBDIALOG_H
43 changes: 42 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4393,6 +4393,11 @@ bool QgsOgrProvider::isSaveAndLoadStyleToDatabaseSupported() const
mGDALDriverName == QLatin1String( "SQLite" );
}

bool QgsOgrProvider::isDeleteStyleFromDatabaseSupported() const
{
return isSaveAndLoadStyleToDatabaseSupported();
}

QString QgsOgrProviderUtils::DatasetIdentification::toString() const
{
return dsName +
Expand Down Expand Up @@ -5765,7 +5770,7 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
if ( !hLayer )
{
// if not create it
// Note: we use the same schema as in the SpatiaLite and postgre providers
// Note: we use the same schema as in the SpatiaLite and postgres providers
//for cross interoperability

char **options = nullptr;
Expand Down Expand Up @@ -5957,6 +5962,42 @@ QGISEXTERN bool saveStyle( const QString &uri, const QString &qmlStyle, const QS
return true;
}


QGISEXTERN bool deleteStyleById( const QString &uri, QString styleId, QString &errCause )
{
QgsDataSourceUri dsUri( uri );
bool deleted;

QgsOgrLayerUniquePtr userLayer = LoadDataSourceAndLayer( uri, errCause );
if ( !userLayer )
return false;

QMutex *mutex = nullptr;
GDALDatasetH hDS = userLayer->getDatasetHandleAndMutex( mutex );
QMutexLocker locker( mutex );

// check if layer_styles table already exist
OGRLayerH hLayer = GDALDatasetGetLayerByName( hDS, "layer_styles" );
if ( !hLayer )
{
errCause = QObject::tr( "Connection to database failed: %1" ).arg( dsUri.uri() );
deleted = false;
}
else
{
if ( OGR_L_DeleteFeature( hLayer, styleId.toInt() ) != OGRERR_NONE )
{
errCause = QObject::tr( "Error executing the delete query." );
deleted = false;
}
else
{
deleted = true;
}
}
return deleted;
}

static
bool LoadDataSourceLayerStylesAndLayer( const QString &uri,
QgsOgrLayerUniquePtr &layerStyles,
Expand Down
1 change: 1 addition & 0 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
bool enterUpdateMode() override { return _enterUpdateMode(); }
bool leaveUpdateMode() override;
bool isSaveAndLoadStyleToDatabaseSupported() const override;
bool isDeleteStyleFromDatabaseSupported() const override;
QString fileVectorFilters() const override;
//! Returns a string containing the available database drivers
QString databaseDrivers() const;
Expand Down
184 changes: 74 additions & 110 deletions src/ui/qgsvectorlayerloadstyledialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,31 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2">
<widget class="QWidget" name="mFromDbWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mStyleTypeComboBox"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QWidget" name="mFromFileWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -39,118 +61,45 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Styles related to the layer</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTableWidget" name="mRelatedTable">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Other styles on the database</string>
<string>File</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QTableWidget" name="mOthersTable">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
<item row="0" column="1">
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mStyleTypeComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<item row="0" column="0">
<widget class="QLabel" name="mModeLabel">
<property name="text">
<string>Categories</string>
<string>Load style</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<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="1">
<widget class="QPushButton" name="mCancelButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mDeleteButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete Style</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="mLoadButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Load Style</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mModeLabel">
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Load style</string>
<string>Categories</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QWidget" name="mFromFileWidget" native="true">
<item row="1" column="1">
<widget class="QListView" name="mStyleCategoriesListView">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_3">
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QWidget" name="mFromDbWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -164,38 +113,53 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label">
<property name="text">
<string>File</string>
<string>Styles related to the layer</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
<item row="1" column="0">
<widget class="QTableWidget" name="mRelatedTable">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Other styles on the database</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QTableWidget" name="mOthersTable">
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<item row="5" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QListView" name="mStyleCategoriesListView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Close|QDialogButtonBox::Open</set>
</property>
</widget>
</item>
Expand Down

0 comments on commit 67b5b67

Please sign in to comment.