QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsdataitemguiproviderutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdataitemguiproviderutils.cpp
3 --------------------------------------
4 Date : June 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgsdataitem.h"
19
20#include <QPointer>
21#include <QMessageBox>
22
23void QgsDataItemGuiProviderUtils::deleteConnectionsPrivate( const QStringList &connectionNames, const std::function<void( const QString & )> &deleteConnection, QPointer<QgsDataItem> firstParent )
24{
25 if ( connectionNames.size() > 1 )
26 {
27 if ( QMessageBox::question( nullptr, QObject::tr( "Remove Connections" ), QObject::tr( "Are you sure you want to remove all %1 selected connections?" ).arg( connectionNames.size() ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
28 return;
29 }
30 else
31 {
32 if ( QMessageBox::question( nullptr, QObject::tr( "Remove Connection" ), QObject::tr( "Are you sure you want to remove the connection to “%1”?" ).arg( connectionNames.at( 0 ) ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
33 return;
34 }
35
36 for ( const QString &connectionName : std::as_const( connectionNames ) )
37 {
38 deleteConnection( connectionName );
39 }
40
41 if ( firstParent )
42 firstParent->refreshConnections();
43}
44
45const QString QgsDataItemGuiProviderUtils::uniqueName( const QString &name, const QStringList &connectionNames )
46{
47 int i = 0;
48 QString newConnectionName( name );
49 while ( connectionNames.contains( newConnectionName ) )
50 {
51 ++i;
52 newConnectionName = QObject::tr( "%1 (copy %2)" ).arg( name ).arg( i );
53 }
54
55 return newConnectionName;
56}
static const QString uniqueName(const QString &name, const QStringList &connectionNames)
Check if connection with name exists in connectionNames list and then try to append a number to it to...