Skip to content
Permalink
Browse files

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.
  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent fe686d3 commit 2e847e2e96613f7a0d95b5107cbf553a44780a60
@@ -586,6 +586,9 @@ Data item that can be used to represent QGIS projects.

virtual bool hasDragEnabled() const;

virtual QgsMimeDataUtils::Uri mimeUri() const;


};

class QgsErrorItem : QgsDataItem
@@ -116,7 +116,7 @@ Splitter has been moved
%End

signals:
void openFile( const QString & );
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
%Docstring
Emitted when a file needs to be opened
%End
@@ -1683,6 +1683,10 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
}
}
}
else if ( u.layerType == QStringLiteral( "project" ) )
{
openFile( u.uri, QStringLiteral( "project" ) );
}
}
}

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


// Open a file specified by a commandline argument, Drop or FileOpen event.
void QgisApp::openFile( const QString &fileName )
void QgisApp::openFile( const QString &fileName, const QString &fileTypeHint )
{
// check to see if we are opening a project file
QFileInfo fi( fileName );
if ( fi.suffix() == QLatin1String( "qgs" ) || fi.suffix() == QLatin1String( "qgz" ) )
if ( fileTypeHint == QStringLiteral( "project" ) || fi.suffix() == QLatin1String( "qgs" ) || fi.suffix() == QLatin1String( "qgz" ) )
{
QgsDebugMsg( "Opening project " + fileName );
openProject( fileName );
@@ -703,7 +703,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Process the list of URIs that have been dropped in QGIS
void handleDropUriList( const QgsMimeDataUtils::UriList &lst );
//! Convenience function to open either a project or a layer file.
void openFile( const QString &fileName );
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
void layerTreeViewDoubleClicked( const QModelIndex &index );
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
void updateNewLayerInsertionPoint();
@@ -467,16 +467,6 @@ QMimeData *QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
if ( index.isValid() )
{
QgsDataItem *ptr = reinterpret_cast< QgsDataItem * >( index.internalPointer() );
if ( ptr->type() == QgsDataItem::Project )
{
QMimeData *mimeData = new QMimeData();
QUrl url = QUrl::fromLocalFile( ptr->path() );
QList<QUrl> urls;
urls << url;
mimeData->setUrls( urls );
return mimeData;
}

QgsMimeDataUtils::Uri uri = ptr->mimeUri();
if ( uri.isValid() )
lst.append( uri );
@@ -1092,6 +1092,15 @@ QgsProjectItem::QgsProjectItem( QgsDataItem *parent, const QString &name, const
setState( Populated ); // no more children
}

QgsMimeDataUtils::Uri QgsProjectItem::mimeUri() const
{
QgsMimeDataUtils::Uri u;
u.layerType = QStringLiteral( "project" );
u.name = mName;
u.uri = mPath;
return u;
}

QgsErrorItem::QgsErrorItem( QgsDataItem *parent, const QString &error, const QString &path )
: QgsDataItem( QgsDataItem::Error, parent, error, path )
{
@@ -598,6 +598,8 @@ class CORE_EXPORT QgsProjectItem : public QgsDataItem

bool hasDragEnabled() const override { return true; }

QgsMimeDataUtils::Uri mimeUri() const override;

};

/**
@@ -63,13 +63,14 @@ class CORE_EXPORT QgsMimeDataUtils
*/
QgsRasterLayer *rasterLayer( bool &owner, QString &error ) const;

//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom" / "project"
QString layerType;

/**
* For "vector" / "raster" type: provider id.
* For "plugin" type: plugin layer type name.
* For "custom" type: key of its QgsCustomDropHandler
* For "project" type: unused
*/
QString providerKey;
//! Human readable name to be used e.g. in layer tree
@@ -361,7 +361,7 @@ void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex &index )
if ( projectItem )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
emit openFile( projectItem->path() );
emit openFile( projectItem->path(), QStringLiteral( "project" ) );
QApplication::restoreOverrideCursor();
}
}
@@ -393,7 +393,7 @@ void QgsBrowserDockWidget::addSelectedLayers()
{
QgsProjectItem *projectItem = qobject_cast<QgsProjectItem *>( item );
if ( projectItem )
emit openFile( projectItem->path() );
emit openFile( projectItem->path(), QStringLiteral( "project" ) );

QApplication::restoreOverrideCursor();
return;
@@ -100,7 +100,7 @@ class GUI_EXPORT QgsBrowserDockWidget : public QgsDockWidget, private Ui::QgsBro

signals:
//! Emitted when a file needs to be opened
void openFile( const QString & );
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
//! Emitted when drop uri list needs to be handled
void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Connections changed in the browser
@@ -106,7 +106,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
//! Emitted when a DB layer was selected for addition: for signal forwarding to QgisApp
void addDatabaseLayers( const QStringList &layerPathList, const QString &providerKey );
//! Emitted when a file needs to be opened
void openFile( const QString & );
void openFile( const QString &fileName, const QString &fileTypeHint = QString() );
//! Emitted when drop uri list needs to be handled from the browser
void handleDropUriList( const QgsMimeDataUtils::UriList & );
//! Update project home directory
@@ -16,11 +16,13 @@

#include "qgspostgresconn.h"
#include "qgspostgresconnpool.h"
#include "qgspostgresprojectstorage.h"
#include "qgscolumntypethread.h"
#include "qgslogger.h"
#include "qgsdatasourceuri.h"
#include "qgsapplication.h"
#include "qgsmessageoutput.h"
#include "qgsprojectstorageregistry.h"
#include "qgsvectorlayer.h"

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

QgsPostgresConnPool::instance()->releaseConnection( conn );

if ( QgsProjectStorage *storage = QgsApplication::projectStorageRegistry()->projectStorageFromType( "postgresql" ) )
{
QgsPostgresProjectUri postUri;
postUri.connInfo = uri;
postUri.schemaName = mName;
QString schemaUri = QgsPostgresProjectStorage::encodeUri( postUri );
const QStringList projectNames = storage->listProjects( schemaUri );
for ( const QString &projectName : projectNames )
{
QgsPostgresProjectUri projectUri( postUri );
projectUri.projectName = projectName;
items.append( new QgsProjectItem( this, projectName, QgsPostgresProjectStorage::encodeUri( projectUri ) ) );
}
}

return items;
}

0 comments on commit 2e847e2

Please sign in to comment.
You can’t perform that action at this time.