Skip to content

Commit f3276de

Browse files
committedMay 27, 2019
Improve empty project item on templates
1 parent 60e5f39 commit f3276de

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

‎src/app/qgstemplateprojectsmodel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ QgsTemplateProjectsModel::QgsTemplateProjectsModel( QObject *parent )
5151

5252
QStandardItem *emptyProjectItem = new QStandardItem();
5353

54-
emptyProjectItem->setData( tr( "New empty project" ), QgsProjectListItemDelegate::TitleRole );
54+
emptyProjectItem->setData( tr( "New Empty Project" ), QgsProjectListItemDelegate::TitleRole );
55+
connect( QgsProject::instance(), &QgsProject::crsChanged, this, [emptyProjectItem]() { emptyProjectItem->setData( QgsProject::instance()->crs().description(), QgsProjectListItemDelegate::CrsRole ); } );
56+
emptyProjectItem->setData( QgsProject::instance()->crs().description(), QgsProjectListItemDelegate::CrsRole );
5557
emptyProjectItem->setFlags( Qt::ItemFlag::ItemIsSelectable | Qt::ItemFlag::ItemIsEnabled ) ;
5658
QSize previewSize( 250, 177 );
5759
QImage image( previewSize, QImage::Format_ARGB32 );
58-
image.fill( Qt::white );
60+
QgsSettings settings;
61+
int myRed = settings.value( QStringLiteral( "qgis/default_canvas_color_red" ), 255 ).toInt();
62+
int myGreen = settings.value( QStringLiteral( "qgis/default_canvas_color_green" ), 255 ).toInt();
63+
int myBlue = settings.value( QStringLiteral( "qgis/default_canvas_color_blue" ), 255 ).toInt();
64+
image.fill( QColor( myRed, myGreen, myBlue ) );
5965
QPainter painter( &image );
6066
painter.setOpacity( 0.5 );
6167
QRect rect( 20, 20, 210, 137 );
@@ -75,7 +81,7 @@ void QgsTemplateProjectsModel::scanDirectory( const QString &path )
7581
QDir dir = QDir( path );
7682
const QFileInfoList files = dir.entryInfoList( QStringList() << QStringLiteral( "*.qgs" ) << QStringLiteral( "*.qgz" ) );
7783

78-
// Remove any template from this directory)
84+
// Remove any template from this directory
7985
for ( int i = rowCount() - 1; i >= 0; --i )
8086
{
8187
if ( index( i, 0 ).data( QgsProjectListItemDelegate::NativePathRole ).toString().startsWith( path ) )

‎src/app/qgswelcomepage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ void QgsWelcomePage::recentProjectItemActivated( const QModelIndex &index )
136136

137137
void QgsWelcomePage::templateProjectItemActivated( const QModelIndex &index )
138138
{
139+
if ( index.data( QgsProjectListItemDelegate::NativePathRole ).isNull() )
140+
QgisApp::instance()->newProject();
139141
QgisApp::instance()->fileNewFromTemplate( index.data( QgsProjectListItemDelegate::NativePathRole ).toString() );
140142
}
141143

0 commit comments

Comments
 (0)
Please sign in to comment.