Skip to content
Permalink
Browse files

Move Project Home GUI action handling from core to app

And remove more QWidget imports from core library
  • Loading branch information
nyalldawson committed Oct 27, 2018
1 parent 48e7e20 commit fab415454a5a4c1974973b43baa8281dfd8a5251
@@ -29,11 +29,7 @@
#include <QInputDialog>
#include <QMessageBox>
#include <QDesktopServices>

QgsAppDirectoryItemGuiProvider::QgsAppDirectoryItemGuiProvider()
{

}
#include <QFileDialog>

QString QgsAppDirectoryItemGuiProvider::name()
{
@@ -214,3 +210,39 @@ void QgsAppDirectoryItemGuiProvider::showProperties( QgsDirectoryItem *item )
dialog->setItem( item );
dialog->show();
}


//
// QgsProjectHomeItemGuiProvider
//

QString QgsProjectHomeItemGuiProvider::name()
{
return QStringLiteral( "project_home_item" );
}

void QgsProjectHomeItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
{
if ( !qobject_cast< QgsProjectHomeItem * >( item ) )
return;

if ( !menu->actions().empty() )
menu->insertSeparator( menu->actions().at( 0 ) );

QAction *setHome = new QAction( tr( "Set Project Home…" ), menu );
connect( setHome, &QAction::triggered, this, [ = ]
{
QString oldHome = QgsProject::instance()->homePath();
QString newPath = QFileDialog::getExistingDirectory( QgisApp::instance(), tr( "Select Project Home Directory" ), oldHome );
if ( !newPath.isEmpty() )
{
QgsProject::instance()->setPresetHomePath( newPath );
}
} );

// ensure item is the first one shown
if ( !menu->actions().empty() )
menu->insertAction( menu->actions().at( 0 ), setHome );
else
menu->addAction( setHome );
}
@@ -31,7 +31,7 @@ class QgsAppDirectoryItemGuiProvider : public QObject, public QgsDataItemGuiProv

public:

QgsAppDirectoryItemGuiProvider();
QgsAppDirectoryItemGuiProvider() = default;

QString name() override;

@@ -49,6 +49,22 @@ class QgsAppDirectoryItemGuiProvider : public QObject, public QgsDataItemGuiProv
};


class QgsProjectHomeItemGuiProvider : public QObject, public QgsDataItemGuiProvider
{
Q_OBJECT

public:

QgsProjectHomeItemGuiProvider() = default;

QString name() override;

void populateContextMenu( QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;

};



#endif // QGSINBUILTDATAITEMPROVIDERS_H

@@ -1026,6 +1026,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mBrowserWidget->setMessageBar( mInfoBar );

QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsAppDirectoryItemGuiProvider() );
QgsGui::instance()->dataItemGuiProviderRegistry()->addProvider( new QgsProjectHomeItemGuiProvider() );

QShortcut *showBrowserDock = new QShortcut( QKeySequence( tr( "Ctrl+2" ) ), this );
connect( showBrowserDock, &QShortcut::activated, mBrowserWidget, &QgsDockWidget::toggleUserVisible );
@@ -27,7 +27,6 @@
#include <QTreeWidgetItem>
#include <QVector>
#include <QStyle>
#include <QFileDialog>
#include <mutex>

#include "qgis.h"
@@ -524,7 +523,7 @@ int QgsDataItem::findItem( QVector<QgsDataItem *> items, QgsDataItem *item )
{
for ( int i = 0; i < items.size(); i++ )
{
Q_ASSERT_X( items[i], "findItem", QString( "item %1 is nullptr" ).arg( i ).toLatin1() );
Q_ASSERT_X( items[i], "findItem", QStringLiteral( "item %1 is nullptr" ).arg( i ).toLatin1() );
QgsDebugMsgLevel( QString::number( i ) + " : " + items[i]->mPath + " x " + item->mPath, 2 );
if ( items[i]->equal( item ) )
return i;
@@ -710,7 +709,7 @@ bool QgsLayerItem::equal( const QgsDataItem *other )
return false;
}
//const QgsLayerItem *o = qobject_cast<const QgsLayerItem *> ( other );
const QgsLayerItem *o = dynamic_cast<const QgsLayerItem *>( other );
const QgsLayerItem *o = qobject_cast<const QgsLayerItem *>( other );
if ( !o )
return false;

@@ -1545,31 +1544,6 @@ QVariant QgsProjectHomeItem::sortKey() const
return QStringLiteral( " 1" );
}

QList<QAction *> QgsProjectHomeItem::actions( QWidget *parent )
{
QList<QAction *> lst = QgsDirectoryItem::actions( parent );
QAction *separator = new QAction( parent );
separator->setSeparator( true );
lst.append( separator );

QAction *setHome = new QAction( tr( "Set Project Home…" ), parent );
connect( setHome, &QAction::triggered, this, [ = ]
{
QWidget *parentWindow = parent;
while ( parentWindow->parentWidget() )
parentWindow = parentWindow->parentWidget();

QString oldHome = QgsProject::instance()->homePath();
QString newPath = QFileDialog::getExistingDirectory( parentWindow, tr( "Select Project Home Directory" ), oldHome );
if ( !newPath.isEmpty() )
{
QgsProject::instance()->setPresetHomePath( newPath );
}
} );
lst << setHome;

return lst;
}

QgsFavoriteItem::QgsFavoriteItem( QgsFavoritesItem *parent, const QString &name, const QString &dirPath, const QString &path )
: QgsDirectoryItem( parent, name, dirPath, path )
@@ -787,9 +787,6 @@ class CORE_EXPORT QgsProjectHomeItem : public QgsDirectoryItem
QIcon icon() override;
QVariant sortKey() const override;

QList<QAction *> actions( QWidget *parent ) override;


};

/**

0 comments on commit fab4154

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