Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates on welcome page #10020

Merged
merged 19 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsproject.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ Returns the current auxiliary storage.
.. versionadded:: 3.0
%End



const QgsProjectMetadata &metadata() const;
%Docstring
Returns a reference to the project's metadata store.
Expand Down Expand Up @@ -1392,6 +1394,7 @@ Emitted when the project dirty status changes.
.. versionadded:: 3.2
%End


public slots:

void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
Expand Down
8 changes: 6 additions & 2 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ SET(QGIS_APP_SRCS
qgsmaplayerstylecategoriesmodel.cpp
qgsmaplayerstyleguiutils.cpp
qgsmapsavedialog.cpp
qgsprojectlistitemdelegate.cpp
qgspuzzlewidget.cpp
qgsversionmigration.cpp
qgsrulebasedlabelingwidget.cpp
Expand All @@ -72,9 +73,10 @@ SET(QGIS_APP_SRCS
qgsstatusbarcoordinateswidget.cpp
qgsstatusbarmagnifierwidget.cpp
qgsstatusbarscalewidget.cpp
qgstemplateprojectsmodel.cpp
qgsvectorlayerloadstyledialog.cpp
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgsrecentprojectsitemsmodel.cpp
qgswelcomepage.cpp

qgsmaptooladdfeature.cpp
Expand Down Expand Up @@ -304,15 +306,17 @@ SET (QGIS_APP_MOC_HDRS
qgsmaplayerstyleguiutils.h
qgsmapsavedialog.h
qgspuzzlewidget.h
qgsprojectlistitemdelegate.h
qgsrulebasedlabelingwidget.h
qgssnappinglayertreemodel.h
qgssnappingwidget.h
qgsstatusbarcoordinateswidget.h
qgsstatusbarmagnifierwidget.h
qgsstatusbarscalewidget.h
qgstemplateprojectsmodel.h
qgsvectorlayerloadstyledialog.h
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgsrecentprojectsitemsmodel.h
qgswelcomepage.h

qgsmaptooladdfeature.h
Expand Down
91 changes: 65 additions & 26 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

connect( mMapCanvas, &QgsMapCanvas::layersChanged, this, &QgisApp::showMapCanvas );

mCentralContainer->setCurrentIndex( mProjOpen ? 0 : 1 );

// a bar to warn the user with non-blocking messages
startProfile( QStringLiteral( "Message bar" ) );
mInfoBar = new QgsMessageBar( centralWidget );
Expand Down Expand Up @@ -924,6 +922,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mSnappingUtils = new QgsMapCanvasSnappingUtils( mMapCanvas, this );
mMapCanvas->setSnappingUtils( mSnappingUtils );
connect( QgsProject::instance(), &QgsProject::snappingConfigChanged, mSnappingUtils, &QgsSnappingUtils::setConfig );
connect( QgsProject::instance(), &QgsProject::collectAttachedFiles, this, &QgisApp::generateProjectAttachedFiles );
connect( mSnappingUtils, &QgsSnappingUtils::configChanged, QgsProject::instance(), &QgsProject::setSnappingConfig );


Expand Down Expand Up @@ -1489,6 +1488,32 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
{
mCentralContainer->setCurrentIndex( 0 );
} );

// As the last thing set the welcome page and restore dock and panel visibility

connect( mCentralContainer, &QStackedWidget::currentChanged, this, [ this ]( int index )
{
QgsSettings settings;

if ( index == 1 ) // welcomepage
{
if ( settings.value( QStringLiteral( "UI/allWidgetsVisible" ), true ).toBool() )
{
toggleReducedView( false );
settings.setValue( QStringLiteral( "UI/widgetsHiddenForWelcomePage" ), true );
}
}
else
{
if ( settings.value( QStringLiteral( "UI/widgetsHiddenForWelcomePage" ), false ).toBool() && !QgsSettings().value( QStringLiteral( "UI/allWidgetsVisible" ), true ).toBool() )
{
toggleReducedView( true );
}
settings.setValue( QStringLiteral( "UI/widgetsHiddenForWelcomePage" ), false );
}
} );

mCentralContainer->setCurrentIndex( 1 );
} // QgisApp ctor

QgisApp::QgisApp()
Expand Down Expand Up @@ -1919,7 +1944,7 @@ void QgisApp::readRecentProjects()
const auto constOldRecentProjects = oldRecentProjects;
for ( const QString &project : constOldRecentProjects )
{
QgsWelcomePageItemsModel::RecentProjectData data;
QgsRecentProjectItemsModel::RecentProjectData data;
data.path = project;
data.title = project;

Expand All @@ -1944,7 +1969,7 @@ void QgisApp::readRecentProjects()
const int maxProjects = QgsSettings().value( QStringLiteral( "maxRecentProjects" ), 20, QgsSettings::App ).toInt();
for ( int i = 0; i < projectKeys.count(); ++i )
{
QgsWelcomePageItemsModel::RecentProjectData data;
QgsRecentProjectItemsModel::RecentProjectData data;
settings.beginGroup( QString::number( projectKeys.at( i ) ) );
data.title = settings.value( QStringLiteral( "title" ) ).toString();
data.path = settings.value( QStringLiteral( "path" ) ).toString();
Expand Down Expand Up @@ -4196,7 +4221,7 @@ void QgisApp::updateRecentProjectPaths()
mRecentProjectsMenu->clear();

const auto constMRecentProjects = mRecentProjects;
for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : constMRecentProjects )
for ( const QgsRecentProjectItemsModel::RecentProjectData &recentProject : constMRecentProjects )
{
QAction *action = mRecentProjectsMenu->addAction( QStringLiteral( "%1 (%2)" ).arg( recentProject.title != recentProject.path ? recentProject.title : QFileInfo( recentProject.path ).completeBaseName(),
QDir::toNativeSeparators( recentProject.path ) ) );
Expand All @@ -4209,7 +4234,7 @@ void QgisApp::updateRecentProjectPaths()
}

std::vector< QgsNative::RecentProjectProperties > recentProjects;
for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : qgis::as_const( mRecentProjects ) )
for ( const QgsRecentProjectItemsModel::RecentProjectData &recentProject : qgis::as_const( mRecentProjects ) )
{
QgsNative::RecentProjectProperties project;
project.title = recentProject.title;
Expand All @@ -4229,7 +4254,7 @@ void QgisApp::saveRecentProjectPath( bool savePreviewImage )
readRecentProjects();

// Get canonical absolute path
QgsWelcomePageItemsModel::RecentProjectData projectData;
QgsRecentProjectItemsModel::RecentProjectData projectData;
projectData.path = QgsProject::instance()->absoluteFilePath();
QString templateDirName = QgsSettings().value( QStringLiteral( "qgis/projectTemplateDir" ),
QgsApplication::qgisSettingsDirPath() + "project_templates" ).toString();
Expand Down Expand Up @@ -4258,18 +4283,7 @@ void QgisApp::saveRecentProjectPath( bool savePreviewImage )
projectData.previewImagePath = QStringLiteral( "%1/%2.png" ).arg( previewDir, fileName );
QDir().mkdir( previewDir );

// Render the map canvas
QSize previewSize( 250, 177 ); // h = w / std::sqrt(2)
QRect previewRect( QPoint( ( mMapCanvas->width() - previewSize.width() ) / 2
, ( mMapCanvas->height() - previewSize.height() ) / 2 )
, previewSize );

QPixmap previewImage( previewSize );
QPainter previewPainter( &previewImage );
mMapCanvas->render( &previewPainter, QRect( QPoint(), previewSize ), previewRect );

// Save
previewImage.save( projectData.previewImagePath );
createPreviewImage( projectData.previewImagePath );
}
else
{
Expand All @@ -4281,8 +4295,7 @@ void QgisApp::saveRecentProjectPath( bool savePreviewImage )
int pinnedCount = 0;
int nonPinnedPos = 0;
bool pinnedTop = true;
const auto constMRecentProjects = mRecentProjects;
for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : constMRecentProjects )
for ( const QgsRecentProjectItemsModel::RecentProjectData &recentProject : qgis::as_const( mRecentProjects ) )
{
if ( recentProject.pin )
{
Expand Down Expand Up @@ -4334,7 +4347,7 @@ void QgisApp::saveRecentProjects()
int idx = 0;

const auto constMRecentProjects = mRecentProjects;
for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : constMRecentProjects )
for ( const QgsRecentProjectItemsModel::RecentProjectData &recentProject : constMRecentProjects )
{
++idx;
settings.beginGroup( QStringLiteral( "UI/recentProjects/%1" ).arg( idx ) );
Expand Down Expand Up @@ -6788,8 +6801,8 @@ void QgisApp::toggleReducedView( bool viewMapOnly )
}
}

this->menuBar()->setVisible( false );
this->statusBar()->setVisible( false );
menuBar()->setVisible( false );
statusBar()->setVisible( false );

settings.setValue( QStringLiteral( "UI/hiddenToolBarsActive" ), toolBarsActive );
}
Expand Down Expand Up @@ -6844,8 +6857,8 @@ void QgisApp::toggleReducedView( bool viewMapOnly )
toolBar->setVisible( true );
}
}
this->menuBar()->setVisible( true );
this->statusBar()->setVisible( true );
menuBar()->setVisible( true );
statusBar()->setVisible( true );

settings.remove( QStringLiteral( "UI/hiddenToolBarsActive" ) );
settings.remove( QStringLiteral( "UI/hiddenDocksTitle" ) );
Expand Down Expand Up @@ -13530,6 +13543,32 @@ void QgisApp::onSnappingConfigChanged()
mSnappingUtils->setConfig( QgsProject::instance()->snappingConfig() );
}

void QgisApp::generateProjectAttachedFiles( QgsStringMap &files )
{
QTemporaryFile *previewImage = new QTemporaryFile( QStringLiteral( "preview-XXXXXXXXXXX.png" ) );
previewImage->open();
previewImage->close();
createPreviewImage( previewImage->fileName() );
files.insert( QStringLiteral( "preview.png" ), previewImage->fileName() );
previewImage->deleteLater();
}

void QgisApp::createPreviewImage( const QString &path )
{
// Render the map canvas
QSize previewSize( 250, 177 ); // h = w / std::sqrt(2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider hi-dpi previews too?

Copy link
Member Author

@m-kuhn m-kuhn May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you save two pictures?
The current one is rendered in "current screen scaling", directly taken from the map canvas (and therefore superfast), so possibilities are a bit constrained.

QRect previewRect( QPoint( ( mMapCanvas->width() - previewSize.width() ) / 2
, ( mMapCanvas->height() - previewSize.height() ) / 2 )
, previewSize );

QPixmap previewImage( previewSize );
QPainter previewPainter( &previewImage );
mMapCanvas->render( &previewPainter, QRect( QPoint(), previewSize ), previewRect );

// Save
previewImage.save( path );
}

void QgisApp::startProfile( const QString &name )
{
QgsApplication::profiler()->start( name );
Expand Down
12 changes: 8 additions & 4 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class QgsNetworkRequestParameters;
#include "qgsconfig.h"
#include "qgspointxy.h"
#include "qgsmimedatautils.h"
#include "qgswelcomepageitemsmodel.h"
#include "qgsrecentprojectsitemsmodel.h"
#include "qgsraster.h"
#include "qgsrasterminmaxorigin.h"
#include "qgsmaplayeractionregistry.h"
Expand Down Expand Up @@ -1062,6 +1062,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
void triggerCrashHandler();

//! Create a new file from a template project
bool fileNewFromTemplate( const QString &fileName );

protected:

//! Handle state changes (WindowTitleChange)
Expand Down Expand Up @@ -1091,6 +1094,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void onSnappingConfigChanged();

void generateProjectAttachedFiles( QgsStringMap &files );

/**
* Triggers validation of the specified \a crs.
*/
Expand Down Expand Up @@ -1314,8 +1319,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void fileOpenAfterLaunch();
//! After project read, set any auto-opened project as successful
void fileOpenedOKAfterLaunch();
//! Create a new file from a template project
bool fileNewFromTemplate( const QString &fileName );
void fileNewFromTemplateAction( QAction *qAction );
void fileNewFromDefaultTemplate();
//! Calculate new rasters from existing ones
Expand Down Expand Up @@ -1763,6 +1766,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void activeLayerChanged( QgsMapLayer *layer );

private:
void createPreviewImage( const QString &path );
void startProfile( const QString &name );
void endProfile();
void functionProfile( void ( QgisApp::*fnc )(), QgisApp *instance, const QString &name );
Expand Down Expand Up @@ -2165,7 +2169,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QSplashScreen *mSplash = nullptr;
//! list of recently opened/saved project files
QList<QgsWelcomePageItemsModel::RecentProjectData> mRecentProjects;
QList<QgsRecentProjectItemsModel::RecentProjectData> mRecentProjects;

//! Currently open layout designer dialogs
QSet<QgsLayoutDesignerDialog *> mLayoutDesignerDialogs;
Expand Down