Skip to content
Permalink
Browse files

[FEATURE][welcome page] Add pin/unpin to list actions (fixes #16394)

  • Loading branch information
nirvn committed Oct 27, 2017
1 parent 30aa5f5 commit edecd49b002599e065d1ec3aef528bb4f95efce6
@@ -413,6 +413,7 @@
<file>themes/default/north_arrow.png</file>
<file>themes/default/diagramNone.svg</file>
<file>themes/default/pie-chart.svg</file>
<file>themes/default/pin.svg</file>
<file>themes/default/pluginExperimental.png</file>
<file>themes/default/pluginDeprecated.png</file>
<file>themes/default/propertyicons/action.svg</file>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="20" height="20" viewBox="0 0 24 24"><path fill="#000000" fill-opacity="0.25" stroke="#FFFFFF" stroke-opacity="0.25" d="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z" /></svg>
@@ -736,7 +736,16 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mRecentProjects.removeAt( row );
saveRecentProjects();
} );

connect( mWelcomePage, &QgsWelcomePage::projectPinned, this, [ this ]( int row )
{
mRecentProjects.at( row ).pin = true;
saveRecentProjects();
} );
connect( mWelcomePage, &QgsWelcomePage::projectUnpinned, this, [ this ]( int row )
{
mRecentProjects.at( row ).pin = false;
saveRecentProjects();
} );
endProfile();

mCentralContainer = new QStackedWidget;
@@ -1657,8 +1666,16 @@ void QgisApp::readRecentProjects()
data.path = settings.value( QStringLiteral( "path" ) ).toString();
data.previewImagePath = settings.value( QStringLiteral( "previewImage" ) ).toString();
data.crs = settings.value( QStringLiteral( "crs" ) ).toString();
data.pin = settings.value( QStringLiteral( "pin" ) ).toBool();
settings.endGroup();
mRecentProjects.append( data );
if ( data.pin )
{
mRecentProjects.prepend( data );
}
else
{
mRecentProjects.append( data );
}
}
settings.endGroup();
}
@@ -3876,9 +3893,16 @@ void QgisApp::saveRecentProjectPath( const QString &projectPath, bool savePrevie
// Prepend this file to the list
mRecentProjects.prepend( projectData );

// Count the number of pinned items, those shouldn't affect trimming
int pinnedCount = 0;
Q_FOREACH ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject, mRecentProjects )
{
if ( recentProject.pin )
pinnedCount++;
}
// Keep the list to 10 items by trimming excess off the bottom
// And remove the associated image
while ( mRecentProjects.count() > 10 )
while ( mRecentProjects.count() > 10 + pinnedCount )
{
QFile( mRecentProjects.takeLast().previewImagePath ).remove();
}
@@ -3907,6 +3931,7 @@ void QgisApp::saveRecentProjects()
settings.setValue( QStringLiteral( "path" ), recentProject.path );
settings.setValue( QStringLiteral( "previewImage" ), recentProject.previewImagePath );
settings.setValue( QStringLiteral( "crs" ), recentProject.crs );
settings.setValue( QStringLiteral( "pin" ), recentProject.pin );
settings.endGroup();
}
}
@@ -117,6 +117,7 @@ void QgsWelcomePage::showContextMenuForProjects( QPoint point )
if ( !index.isValid() )
return;

bool pin = mModel->data( index, QgsWelcomePageItemsModel::PinRole ).toBool();
QString path = mModel->data( index, QgsWelcomePageItemsModel::PathRole ).toString();
if ( path.isEmpty() )
return;
@@ -127,6 +128,26 @@ void QgsWelcomePage::showContextMenuForProjects( QPoint point )

if ( enabled )
{
if ( !pin )
{
QAction *pinAction = new QAction( tr( "Pin to List" ), menu );
connect( pinAction, &QAction::triggered, this, [this, index]
{
mModel->pinProject( index );
emit projectPinned( index.row() );
} );
menu->addAction( pinAction );
}
else
{
QAction *pinAction = new QAction( tr( "Unpin from List" ), menu );
connect( pinAction, &QAction::triggered, this, [this, index]
{
mModel->unpinProject( index );
emit projectUnpinned( index.row() );
} );
menu->addAction( pinAction );
}
QAction *openFolderAction = new QAction( tr( "Open Directory…" ), menu );
connect( openFolderAction, &QAction::triggered, this, [this, path]
{
@@ -37,6 +37,8 @@ class QgsWelcomePage : public QWidget

signals:
void projectRemoved( int row );
void projectPinned( int row );
void projectUnpinned( int row );

private slots:
void itemActivated( const QModelIndex &index );
@@ -75,8 +75,9 @@ void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionVie
int titleSize = QApplication::fontMetrics().height() * 1.1;
int textSize = titleSize * 0.85;

doc.setHtml( QStringLiteral( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize )
doc.setHtml( QStringLiteral( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3%4</span><br>%5<br>%6</div>" ).arg( textSize ).arg( titleSize )
.arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString(),
index.data( QgsWelcomePageItemsModel::PinRole ).toBool() == true ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
@@ -111,8 +112,9 @@ QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem &option,
int titleSize = QApplication::fontMetrics().height() * 1.1;
int textSize = titleSize * 0.85;

doc.setHtml( QStringLiteral( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize )
doc.setHtml( QStringLiteral( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3%4</span><br>%5<br>%6</div>" ).arg( textSize ).arg( titleSize )
.arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString(),
index.data( QgsWelcomePageItemsModel::PinRole ).toBool() == true ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( width - ( !icon.isNull() ? icon.width() + 35 : 35 ) );
@@ -161,6 +163,8 @@ QVariant QgsWelcomePageItemsModel::data( const QModelIndex &index, int role ) co
{
return QString();
}
case PinRole:
return mRecentProjects.at( index.row() ).pin;
case Qt::DecorationRole:
{
QString filename( mRecentProjects.at( index.row() ).previewImagePath );
@@ -214,6 +218,16 @@ Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const
return flags;
}

void QgsWelcomePageItemsModel::pinProject( const QModelIndex &index )
{
mRecentProjects.at( index.row() ).pin = true;
}

void QgsWelcomePageItemsModel::unpinProject( const QModelIndex &index )
{
mRecentProjects.at( index.row() ).pin = false;
}

void QgsWelcomePageItemsModel::removeProject( const QModelIndex &index )
{
mRecentProjects.removeAt( index.row() );
@@ -40,7 +40,8 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
TitleRole = Qt::UserRole + 1,
PathRole = Qt::UserRole + 2,
NativePathRole = Qt::UserRole + 3,
CrsRole = Qt::UserRole + 4
CrsRole = Qt::UserRole + 4,
PinRole = Qt::UserRole + 5
};

struct RecentProjectData
@@ -50,6 +51,7 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
QString title;
QString previewImagePath;
QString crs;
mutable bool pin = false;
mutable bool checkedExists = false;
mutable bool exists = false;
};
@@ -62,6 +64,8 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
QVariant data( const QModelIndex &index, int role ) const override;
Qt::ItemFlags flags( const QModelIndex &index ) const override;

void pinProject( const QModelIndex &index );
void unpinProject( const QModelIndex &index );
void removeProject( const QModelIndex &index );
void recheckProject( const QModelIndex &index );

0 comments on commit edecd49

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