Skip to content

Commit

Permalink
Disable unavailable projects
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 19, 2015
1 parent 9bce9ed commit 10dfb5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/app/qgswelcomepageitemsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include "qgswelcomepageitemsmodel.h"

#include <QPixmap>
#include <QFile>

QgsWelcomePageItemsModel::QgsWelcomePageItemsModel(QObject* parent)
: QAbstractListModel( parent )
QgsWelcomePageItemsModel::QgsWelcomePageItemsModel( QObject* parent )
: QAbstractListModel( parent )
{

}
Expand All @@ -31,15 +32,16 @@ void QgsWelcomePageItemsModel::setRecentProjects( const QList<RecentProjectData>
}


int QgsWelcomePageItemsModel::rowCount(const QModelIndex& parent) const
int QgsWelcomePageItemsModel::rowCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent )
return mRecentProjects.size();
}

QVariant QgsWelcomePageItemsModel::data(const QModelIndex& index, int role) const
QVariant QgsWelcomePageItemsModel::data( const QModelIndex& index, int role ) const
{
switch ( role ) {
switch ( role )
{
case Qt::DisplayRole:
return mRecentProjects.at( index.row() ).title;
break;
Expand All @@ -54,8 +56,23 @@ QVariant QgsWelcomePageItemsModel::data(const QModelIndex& index, int role) cons

case Qt::ToolTipRole:
return mRecentProjects.at( index.row() ).path;
break;

default:
return QVariant();
}
}


Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex& index ) const
{
Qt::ItemFlags flags = QAbstractItemModel::flags( index );

const RecentProjectData& projectData = mRecentProjects.at( index.row() );

if ( !QFile::exists(( projectData.path ) ) )
flags &= ~Qt::ItemIsEnabled;

return flags;

}
1 change: 1 addition & 0 deletions src/app/qgswelcomepageitemsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class QgsWelcomePageItemsModel : public QAbstractListModel

int rowCount( const QModelIndex& parent ) const;
QVariant data( const QModelIndex& index, int role ) const;
Qt::ItemFlags flags( const QModelIndex& index ) const;

private:
QList<RecentProjectData> mRecentProjects;
Expand Down

0 comments on commit 10dfb5b

Please sign in to comment.