8
8
#include " qgsprojectstorage.h"
9
9
#include " qgsprojectstorageregistry.h"
10
10
11
+ #include < QMenu>
11
12
#include < QMessageBox>
13
+ #include < QPushButton>
12
14
13
15
QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog ( bool saving, QWidget *parent )
14
16
: QDialog( parent )
@@ -18,6 +20,12 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q
18
20
19
21
connect ( buttonBox, &QDialogButtonBox::accepted, this , &QgsPostgresProjectStorageDialog::onOK );
20
22
23
+ QPushButton *btnManageProjects = new QPushButton ( tr ( " Manage Projects" ), this );
24
+ QMenu *menuManageProjects = new QMenu ( btnManageProjects );
25
+ mActionRemoveProject = menuManageProjects->addAction ( tr ( " Remove Project" ), this , &QgsPostgresProjectStorageDialog::removeProject );
26
+ btnManageProjects->setMenu ( menuManageProjects );
27
+ buttonBox->addButton ( btnManageProjects, QDialogButtonBox::ActionRole );
28
+
21
29
if ( saving )
22
30
{
23
31
setWindowTitle ( tr ( " Save project to PostgreSQL" ) );
@@ -38,6 +46,9 @@ QgsPostgresProjectStorageDialog::QgsPostgresProjectStorageDialog( bool saving, Q
38
46
mCboConnection ->setCurrentIndex ( mCboConnection ->findText ( toSelect ) );
39
47
40
48
connect ( mCboSchema , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsPostgresProjectStorageDialog::populateProjects );
49
+ connect ( mCboProject , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsPostgresProjectStorageDialog::projectChanged );
50
+
51
+ projectChanged ();
41
52
}
42
53
43
54
QString QgsPostgresProjectStorageDialog::connectionName () const
@@ -89,20 +100,19 @@ void QgsPostgresProjectStorageDialog::populateSchemas()
89
100
{
90
101
mCboSchema ->addItem ( schema.name );
91
102
}
103
+
104
+ projectChanged ();
92
105
}
93
106
94
107
void QgsPostgresProjectStorageDialog::populateProjects ()
95
108
{
96
109
mCboProject ->clear ();
97
110
98
- QgsPostgresProjectUri postUri;
99
- postUri.connInfo = QgsPostgresConn::connUri ( mCboConnection ->currentText () );
100
- postUri.schemaName = mCboSchema ->currentText ();
101
- QString uri = QgsPostgresProjectStorage::makeUri ( postUri );
102
-
111
+ QString uri = currentProjectUri ();
103
112
QgsProjectStorage *storage = QgsApplication::projectStorageRegistry ()->projectStorageFromType ( " postgresql" );
104
113
Q_ASSERT ( storage );
105
114
mCboProject ->addItems ( storage->listProjects ( uri ) );
115
+ projectChanged ();
106
116
}
107
117
108
118
void QgsPostgresProjectStorageDialog::onOK ()
@@ -125,3 +135,32 @@ void QgsPostgresProjectStorageDialog::onOK()
125
135
126
136
accept ();
127
137
}
138
+
139
+ void QgsPostgresProjectStorageDialog::projectChanged ()
140
+ {
141
+ mActionRemoveProject ->setEnabled ( mCboProject ->count () != 0 && mCboProject ->findText ( mCboProject ->currentText () ) != -1 );
142
+ }
143
+
144
+ void QgsPostgresProjectStorageDialog::removeProject ()
145
+ {
146
+ int res = QMessageBox::question ( this , tr ( " Remove project" ),
147
+ tr ( " Do you really want to remove the project \" %1\" ?" ).arg ( mCboProject ->currentText () ),
148
+ QMessageBox::Yes | QMessageBox::No );
149
+ if ( res != QMessageBox::Yes )
150
+ return ;
151
+
152
+ QgsProjectStorage *storage = QgsApplication::projectStorageRegistry ()->projectStorageFromType ( " postgresql" );
153
+ Q_ASSERT ( storage );
154
+ storage->removeProject ( currentProjectUri () );
155
+ populateProjects ();
156
+ }
157
+
158
+ QString QgsPostgresProjectStorageDialog::currentProjectUri ( bool schemaOnly )
159
+ {
160
+ QgsPostgresProjectUri postUri;
161
+ postUri.connInfo = QgsPostgresConn::connUri ( mCboConnection ->currentText () );
162
+ postUri.schemaName = mCboSchema ->currentText ();
163
+ if ( !schemaOnly )
164
+ postUri.projectName = mCboProject ->currentText ();
165
+ return QgsPostgresProjectStorage::encodeUri ( postUri );
166
+ }
0 commit comments