Skip to content

Commit 2e847e2

Browse files
committed
Support for project items in browser for PostgreSQL
Switched from using URLs in mime data to URI list for drag-n-drop of projects so that they are handled in the same way as the other browser items.
1 parent fe686d3 commit 2e847e2

12 files changed

+46
-19
lines changed

python/core/qgsdataitem.sip.in

+3
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ Data item that can be used to represent QGIS projects.
586586

587587
virtual bool hasDragEnabled() const;
588588

589+
virtual QgsMimeDataUtils::Uri mimeUri() const;
590+
591+
589592
};
590593

591594
class QgsErrorItem : QgsDataItem

python/gui/qgsbrowserdockwidget.sip.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Splitter has been moved
116116
%End
117117

118118
signals:
119-
void openFile( const QString & );
119+
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
120120
%Docstring
121121
Emitted when a file needs to be opened
122122
%End

src/app/qgisapp.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,10 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
16831683
}
16841684
}
16851685
}
1686+
else if ( u.layerType == QStringLiteral( "project" ) )
1687+
{
1688+
openFile( u.uri, QStringLiteral( "project" ) );
1689+
}
16861690
}
16871691
}
16881692

@@ -6049,11 +6053,11 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
60496053

60506054

60516055
// Open a file specified by a commandline argument, Drop or FileOpen event.
6052-
void QgisApp::openFile( const QString &fileName )
6056+
void QgisApp::openFile( const QString &fileName, const QString &fileTypeHint )
60536057
{
60546058
// check to see if we are opening a project file
60556059
QFileInfo fi( fileName );
6056-
if ( fi.suffix() == QLatin1String( "qgs" ) || fi.suffix() == QLatin1String( "qgz" ) )
6060+
if ( fileTypeHint == QStringLiteral( "project" ) || fi.suffix() == QLatin1String( "qgs" ) || fi.suffix() == QLatin1String( "qgz" ) )
60576061
{
60586062
QgsDebugMsg( "Opening project " + fileName );
60596063
openProject( fileName );

src/app/qgisapp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
703703
//! Process the list of URIs that have been dropped in QGIS
704704
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
705705
//! Convenience function to open either a project or a layer file.
706-
void openFile( const QString &fileName );
706+
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
707707
void layerTreeViewDoubleClicked( const QModelIndex &index );
708708
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
709709
void updateNewLayerInsertionPoint();

src/core/qgsbrowsermodel.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,6 @@ QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
467467
if ( index.isValid() )
468468
{
469469
QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
470-
if ( ptr->type() == QgsDataItem::Project )
471-
{
472-
QMimeData *mimeData = new QMimeData();
473-
QUrl url = QUrl::fromLocalFile( ptr->path() );
474-
QList<QUrl> urls;
475-
urls << url;
476-
mimeData->setUrls( urls );
477-
return mimeData;
478-
}
479-
480470
QgsMimeDataUtils::Uri uri = ptr->mimeUri();
481471
if ( uri.isValid() )
482472
lst.append( uri );

src/core/qgsdataitem.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,15 @@ QgsProjectItem::QgsProjectItem( QgsDataItem *parent, const QString &name, const
10921092
setState( Populated ); // no more children
10931093
}
10941094

1095+
QgsMimeDataUtils::Uri QgsProjectItem::mimeUri() const
1096+
{
1097+
QgsMimeDataUtils::Uri u;
1098+
u.layerType = QStringLiteral( "project" );
1099+
u.name = mName;
1100+
u.uri = mPath;
1101+
return u;
1102+
}
1103+
10951104
QgsErrorItem::QgsErrorItem( QgsDataItem *parent, const QString &error, const QString &path )
10961105
: QgsDataItem( QgsDataItem::Error, parent, error, path )
10971106
{

src/core/qgsdataitem.h

+2
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ class CORE_EXPORT QgsProjectItem : public QgsDataItem
598598

599599
bool hasDragEnabled() const override { return true; }
600600

601+
QgsMimeDataUtils::Uri mimeUri() const override;
602+
601603
};
602604

603605
/**

src/core/qgsmimedatautils.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ class CORE_EXPORT QgsMimeDataUtils
6363
*/
6464
QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;
6565

66-
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
66+
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom" / "project"
6767
QString layerType;
6868

6969
/**
7070
* For "vector" / "raster" type: provider id.
7171
* For "plugin" type: plugin layer type name.
7272
* For "custom" type: key of its QgsCustomDropHandler
73+
* For "project" type: unused
7374
*/
7475
QString providerKey;
7576
//! Human readable name to be used e.g. in layer tree

src/gui/qgsbrowserdockwidget.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
361361
if ( projectItem )
362362
{
363363
QApplication::setOverrideCursor( Qt::WaitCursor );
364-
emit openFile( projectItem->path() );
364+
emit openFile( projectItem->path(), QStringLiteral( "project" ) );
365365
QApplication::restoreOverrideCursor();
366366
}
367367
}
@@ -393,7 +393,7 @@ void QgsBrowserDockWidget::addSelectedLayers()
393393
{
394394
QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
395395
if ( projectItem )
396-
emit openFile( projectItem->path() );
396+
emit openFile( projectItem->path(), QStringLiteral( "project" ) );
397397

398398
QApplication::restoreOverrideCursor();
399399
return;

src/gui/qgsbrowserdockwidget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro
100100

101101
signals:
102102
//! Emitted when a file needs to be opened
103-
void openFile( const QString & );
103+
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
104104
//! Emitted when drop uri list needs to be handled
105105
void handleDropUriList( const QgsMimeDataUtils::UriList & );
106106
//! Connections changed in the browser

src/gui/qgsdatasourcemanagerdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
106106
//! Emitted when a DB layer was selected for addition: for signal forwarding to QgisApp
107107
void addDatabaseLayers( const QStringList &layerPathList, const QString &providerKey );
108108
//! Emitted when a file needs to be opened
109-
void openFile( const QString & );
109+
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
110110
//! Emitted when drop uri list needs to be handled from the browser
111111
void handleDropUriList( const QgsMimeDataUtils::UriList & );
112112
//! Update project home directory

src/providers/postgres/qgspostgresdataitems.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
#include "qgspostgresconn.h"
1818
#include "qgspostgresconnpool.h"
19+
#include "qgspostgresprojectstorage.h"
1920
#include "qgscolumntypethread.h"
2021
#include "qgslogger.h"
2122
#include "qgsdatasourceuri.h"
2223
#include "qgsapplication.h"
2324
#include "qgsmessageoutput.h"
25+
#include "qgsprojectstorageregistry.h"
2426
#include "qgsvectorlayer.h"
2527

2628
#ifdef HAVE_GUI
@@ -573,6 +575,22 @@ QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
573575
}
574576

575577
QgsPostgresConnPool::instance()->releaseConnection( conn );
578+
579+
if ( QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" ) )
580+
{
581+
QgsPostgresProjectUri postUri;
582+
postUri.connInfo = uri;
583+
postUri.schemaName = mName;
584+
QString schemaUri = QgsPostgresProjectStorage::encodeUri( postUri );
585+
const QStringList projectNames = storage->listProjects( schemaUri );
586+
for ( const QString &projectName : projectNames )
587+
{
588+
QgsPostgresProjectUri projectUri( postUri );
589+
projectUri.projectName = projectName;
590+
items.append( new QgsProjectItem( this, projectName, QgsPostgresProjectStorage::encodeUri( projectUri ) ) );
591+
}
592+
}
593+
576594
return items;
577595
}
578596

0 commit comments

Comments
 (0)