Skip to content

Commit

Permalink
Hide recent projects if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 27, 2019
1 parent e27cca5 commit 91ea9ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/app/qgswelcomepage.cpp
Expand Up @@ -56,9 +56,9 @@ QgsWelcomePage::QgsWelcomePage( bool skipVersionCheck, QWidget *parent )
centerLayout->setMargin( 0 );

int titleSize = static_cast<int>( QApplication::fontMetrics().height() * 1.4 );
QLabel *recentProjectsTitle = new QLabel( QStringLiteral( "<div style='font-size:%1px;font-weight:bold'>%2</div>" ).arg( QString::number( titleSize ), tr( "Recent Projects" ) ) );
recentProjectsTitle->setContentsMargins( titleSize / 2, titleSize / 6, 0, 0 );
centerLayout->addWidget( recentProjectsTitle, 0, 0 );
mRecentProjectsTitle = new QLabel( QStringLiteral( "<div style='font-size:%1px;font-weight:bold'>%2</div>" ).arg( QString::number( titleSize ), tr( "Recent Projects" ) ) );
mRecentProjectsTitle->setContentsMargins( titleSize / 2, titleSize / 6, 0, 0 );
centerLayout->addWidget( mRecentProjectsTitle, 0, 0 );

mRecentProjectsListView = new QListView();
mRecentProjectsListView->setResizeMode( QListView::Adjust );
Expand Down Expand Up @@ -121,6 +121,7 @@ QgsWelcomePage::~QgsWelcomePage()
void QgsWelcomePage::setRecentProjects( const QList<QgsRecentProjectItemsModel::RecentProjectData> &recentProjects )
{
mRecentProjectsModel->setRecentProjects( recentProjects );
updateRecentProjectsVisibility();
}

void QgsWelcomePage::recentProjectItemActivated( const QModelIndex &index )
Expand Down Expand Up @@ -255,3 +256,10 @@ void QgsWelcomePage::showContextMenuForTemplates( QPoint point )

menu->popup( mTemplateProjectsListView->mapToGlobal( point ) );
}

void QgsWelcomePage::updateRecentProjectsVisibility()
{
bool visible = mRecentProjectsModel->rowCount() > 0;
mRecentProjectsListView->setVisible( visible );
mRecentProjectsTitle->setVisible( visible );
}
4 changes: 4 additions & 0 deletions src/app/qgswelcomepage.h
Expand Up @@ -25,6 +25,7 @@

class QgsVersionInfo;
class QListView;
class QLabel;

class QgsWelcomePage : public QWidget
{
Expand All @@ -50,10 +51,13 @@ class QgsWelcomePage : public QWidget
void showContextMenuForTemplates( QPoint point );

private:
void updateRecentProjectsVisibility();

QgsRecentProjectItemsModel *mRecentProjectsModel = nullptr;
QTextBrowser *mVersionInformation = nullptr;
QgsVersionInfo *mVersionInfo = nullptr;
QListView *mRecentProjectsListView = nullptr;
QLabel *mRecentProjectsTitle = nullptr;
QListView *mTemplateProjectsListView = nullptr;
QStandardItemModel *mTemplateProjectsModel = nullptr;
};
Expand Down

0 comments on commit 91ea9ed

Please sign in to comment.