|
39 | 39 | #include "qgstaskmanager.h"
|
40 | 40 | #include "qgsproviderregistry.h"
|
41 | 41 | #include "qgsproxyprogresstask.h"
|
42 |
| -#include "qgssqliteutils.h" |
43 | 42 |
|
44 | 43 | QGISEXTERN bool deleteLayer( const QString &uri, const QString &errCause );
|
45 | 44 |
|
@@ -744,86 +743,3 @@ bool QgsGeoPackageVectorLayerItem::executeDeleteLayer( QString &errCause )
|
744 | 743 | return ::deleteLayer( mUri, errCause );
|
745 | 744 | }
|
746 | 745 |
|
747 |
| -bool QgsGeoPackageVectorLayerItem::rename( const QString &name ) |
748 |
| -{ |
749 |
| - // Checks that name does not exist yet |
750 |
| - if ( tableNames().contains( name ) ) |
751 |
| - { |
752 |
| - return false; |
753 |
| - } |
754 |
| - // Check if the layer(s) are in the registry |
755 |
| - const QList<QgsMapLayer *> layersList( layersInProject() ); |
756 |
| - if ( ! layersList.isEmpty( ) ) |
757 |
| - { |
758 |
| - if ( QMessageBox::question( nullptr, QObject::tr( "Rename Layer" ), QObject::tr( "The layer <b>%1</b> is loaded in the current project with name <b>%2</b>," |
759 |
| - " do you want to remove it from the project and rename it?" ).arg( mName, layersList.at( 0 )->name() ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes ) |
760 |
| - { |
761 |
| - return false; |
762 |
| - } |
763 |
| - } |
764 |
| - if ( ! layersList.isEmpty() ) |
765 |
| - { |
766 |
| - QgsProject::instance()->removeMapLayers( layersList ); |
767 |
| - } |
768 |
| - |
769 |
| - const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, mUri ); |
770 |
| - QString errCause; |
771 |
| - if ( parts.empty() || parts.value( QStringLiteral( "path" ) ).isNull() || parts.value( QStringLiteral( "layerName" ) ).isNull() ) |
772 |
| - { |
773 |
| - errCause = QObject::tr( "Layer URI %1 is not valid!" ).arg( mUri ); |
774 |
| - } |
775 |
| - else |
776 |
| - { |
777 |
| - QString filePath = parts.value( QStringLiteral( "path" ) ).toString(); |
778 |
| - const QList<QgsMapLayer *> layersList( layersInProject() ); |
779 |
| - if ( ! layersList.isEmpty( ) ) |
780 |
| - { |
781 |
| - if ( QMessageBox::question( nullptr, QObject::tr( "Rename Layer" ), QObject::tr( "The layer <b>%1</b> exists in the current project <b>%2</b>," |
782 |
| - " do you want to remove it from the project and rename it?" ).arg( mName, layersList.at( 0 )->name() ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes ) |
783 |
| - { |
784 |
| - return false; |
785 |
| - } |
786 |
| - } |
787 |
| - if ( ! layersList.isEmpty() ) |
788 |
| - { |
789 |
| - QgsProject::instance()->removeMapLayers( layersList ); |
790 |
| - } |
791 |
| - |
792 |
| - // TODO: maybe an index? |
793 |
| - QString oldName = parts.value( QStringLiteral( "layerName" ) ).toString(); |
794 |
| - |
795 |
| - GDALDatasetH hDS = GDALOpenEx( filePath.toUtf8().constData(), GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ); |
796 |
| - if ( hDS ) |
797 |
| - { |
798 |
| - QString sql( QStringLiteral( "ALTER TABLE %1 RENAME TO %2" ) |
799 |
| - .arg( QgsSqliteUtils::quotedIdentifier( oldName ), |
800 |
| - QgsSqliteUtils::quotedIdentifier( name ) ) ); |
801 |
| - OGRLayerH ogrLayer( GDALDatasetExecuteSQL( hDS, sql.toUtf8().constData(), nullptr, nullptr ) ); |
802 |
| - if ( ogrLayer ) |
803 |
| - GDALDatasetReleaseResultSet( hDS, ogrLayer ); |
804 |
| - errCause = CPLGetLastErrorMsg( ); |
805 |
| - if ( errCause.isEmpty() ) |
806 |
| - { |
807 |
| - sql = QStringLiteral( "UPDATE layer_styles SET f_table_name = %2 WHERE f_table_name = %1" ) |
808 |
| - .arg( QgsSqliteUtils::quotedString( oldName ), |
809 |
| - QgsSqliteUtils::quotedString( name ) ); |
810 |
| - ogrLayer = GDALDatasetExecuteSQL( hDS, sql.toUtf8().constData(), nullptr, nullptr ); |
811 |
| - if ( ogrLayer ) |
812 |
| - GDALDatasetReleaseResultSet( hDS, ogrLayer ); |
813 |
| - } |
814 |
| - GDALClose( hDS ); |
815 |
| - } |
816 |
| - else |
817 |
| - { |
818 |
| - errCause = QObject::tr( "There was an error opening %1!" ).arg( filePath ); |
819 |
| - } |
820 |
| - } |
821 |
| - |
822 |
| - if ( ! errCause.isEmpty() ) |
823 |
| - QMessageBox::critical( nullptr, QObject::tr( "Error renaming layer" ), errCause ); |
824 |
| - else if ( mParent ) |
825 |
| - mParent->refreshConnections(); |
826 |
| - |
827 |
| - return errCause.isEmpty(); |
828 |
| -} |
829 |
| - |
0 commit comments