QGIS API Documentation 3.39.0-Master (9ea1ddbe645)
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,
28 QObject::tr( "Remove Connections" ),
29 QObject::tr( "Are you sure you want to remove all %1 selected connections?" ).arg( connectionNames.size() ),
30 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
31 return;
32 }
33 else
34 {
35 if ( QMessageBox::question( nullptr, QObject::tr( "Remove Connection" ),
36 QObject::tr( "Are you sure you want to remove the connection to “%1”?" ).arg( connectionNames.at( 0 ) ),
37 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
38 return;
39 }
40
41 for ( const QString &connectionName : std::as_const( connectionNames ) )
42 {
43 deleteConnection( connectionName );
44 }
45
46 if ( firstParent )
47 firstParent->refreshConnections();
48}
49
50const QString QgsDataItemGuiProviderUtils::uniqueName( const QString &name, const QStringList &connectionNames )
51{
52 int i = 0;
53 QString newConnectionName( name );
54 while ( connectionNames.contains( newConnectionName ) )
55 {
56 ++i;
57 newConnectionName = QObject::tr( "%1 (copy %2)" ).arg( name ) .arg( i );
58 }
59
60 return newConnectionName;
61}
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...