Skip to content

Commit

Permalink
Rename welcomepageitemsmodel to recentprojectsitemmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 27, 2019
1 parent 169e246 commit e283fb9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SET(QGIS_APP_SRCS
qgsstatusbarscalewidget.cpp
qgsvectorlayerloadstyledialog.cpp
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgsrecentprojectsitemsmodel.cpp
qgswelcomepage.cpp

qgsmaptooladdfeature.cpp
Expand Down Expand Up @@ -312,7 +312,7 @@ SET (QGIS_APP_MOC_HDRS
qgsstatusbarscalewidget.h
qgsvectorlayerloadstyledialog.h
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgsrecentprojectsitemsmodel.h
qgswelcomepage.h

qgsmaptooladdfeature.h
Expand Down
14 changes: 7 additions & 7 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,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 +1944,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 +4196,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 +4209,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 +4229,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 @@ -4282,7 +4282,7 @@ void QgisApp::saveRecentProjectPath( bool savePreviewImage )
int nonPinnedPos = 0;
bool pinnedTop = true;
const auto constMRecentProjects = mRecentProjects;
for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : constMRecentProjects )
for ( const QgsRecentProjectItemsModel::RecentProjectData &recentProject : constMRecentProjects )
{
if ( recentProject.pin )
{
Expand Down Expand Up @@ -4334,7 +4334,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
4 changes: 2 additions & 2 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 @@ -2165,7 +2165,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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* *
***************************************************************************/

#include "qgswelcomepageitemsmodel.h"
#include "qgsrecentprojectsitemsmodel.h"

#include "qgsapplication.h"
#include "qgscoordinatereferencesystem.h"
Expand All @@ -29,14 +29,14 @@
#include <QTextDocument>
#include <QDir>

QgsWelcomePageItemDelegate::QgsWelcomePageItemDelegate( QObject *parent )
QgsRecentProjectItemDelegate::QgsRecentProjectItemDelegate( QObject *parent )
: QStyledItemDelegate( parent )
, mRoundedRectSizePixels( Qgis::UI_SCALE_FACTOR * QApplication::fontMetrics().height() * 0.5 )
{

}

void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
void QgsRecentProjectItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
painter->save();

Expand Down Expand Up @@ -81,10 +81,10 @@ void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionVie
int textSize = titleSize * 0.85;

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() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
.arg( index.data( QgsRecentProjectItemsModel::TitleRole ).toString(),
index.data( QgsRecentProjectItemsModel::PinRole ).toBool() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsRecentProjectItemsModel::NativePathRole ).toString(),
index.data( QgsRecentProjectItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( option.rect.width() - ( !icon.isNull() ? icon.width() + 4.375 * mRoundedRectSizePixels : 4.375 * mRoundedRectSizePixels ) );

if ( !icon.isNull() )
Expand All @@ -99,7 +99,7 @@ void QgsWelcomePageItemDelegate::paint( QPainter *painter, const QStyleOptionVie
painter->restore();
}

QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
QSize QgsRecentProjectItemDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QTextDocument doc;
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
Expand All @@ -118,36 +118,36 @@ QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem &option,
int textSize = titleSize * 0.85;

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() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsWelcomePageItemsModel::NativePathRole ).toString(),
index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
.arg( index.data( QgsRecentProjectItemsModel::TitleRole ).toString(),
index.data( QgsRecentProjectItemsModel::PinRole ).toBool() ? QStringLiteral( "<img src=\"qrc:/images/themes/default/pin.svg\">" ) : QString(),
index.data( QgsRecentProjectItemsModel::NativePathRole ).toString(),
index.data( QgsRecentProjectItemsModel::CrsRole ).toString() ) );
doc.setTextWidth( width - ( !icon.isNull() ? icon.width() + 4.375 * mRoundedRectSizePixels : 4.375 * mRoundedRectSizePixels ) );

return QSize( width, std::max( ( double ) doc.size().height() + 1.25 * mRoundedRectSizePixels, static_cast<double>( icon.height() ) ) + 2.5 * mRoundedRectSizePixels );
}

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

}

void QgsWelcomePageItemsModel::setRecentProjects( const QList<RecentProjectData> &recentProjects )
void QgsRecentProjectItemsModel::setRecentProjects( const QList<RecentProjectData> &recentProjects )
{
beginResetModel();
mRecentProjects = recentProjects;
endResetModel();
}


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

QVariant QgsWelcomePageItemsModel::data( const QModelIndex &index, int role ) const
QVariant QgsRecentProjectItemsModel::data( const QModelIndex &index, int role ) const
{
switch ( role )
{
Expand Down Expand Up @@ -204,7 +204,7 @@ QVariant QgsWelcomePageItemsModel::data( const QModelIndex &index, int role ) co
}


Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const
Qt::ItemFlags QgsRecentProjectItemsModel::flags( const QModelIndex &index ) const
{
if ( !index.isValid() || !rowCount( index.parent() ) )
return Qt::NoItemFlags;
Expand All @@ -231,24 +231,24 @@ Qt::ItemFlags QgsWelcomePageItemsModel::flags( const QModelIndex &index ) const
return flags;
}

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

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

void QgsWelcomePageItemsModel::removeProject( const QModelIndex &index )
void QgsRecentProjectItemsModel::removeProject( const QModelIndex &index )
{
beginRemoveRows( index, index.row(), index.row() );
mRecentProjects.removeAt( index.row() );
endRemoveRows();
}

void QgsWelcomePageItemsModel::recheckProject( const QModelIndex &index )
void QgsRecentProjectItemsModel::recheckProject( const QModelIndex &index )
{
const RecentProjectData &projectData = mRecentProjects.at( index.row() );
projectData.exists = QFile::exists( ( projectData.path ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include <QStringList>
#include <QStyledItemDelegate>

class QgsWelcomePageItemDelegate : public QStyledItemDelegate
class QgsRecentProjectItemDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:
explicit QgsWelcomePageItemDelegate( QObject *parent = nullptr );
explicit QgsRecentProjectItemDelegate( QObject *parent = nullptr );
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;

Expand All @@ -34,7 +34,7 @@ class QgsWelcomePageItemDelegate : public QStyledItemDelegate
int mRoundedRectSizePixels = 5;
};

class QgsWelcomePageItemsModel : public QAbstractListModel
class QgsRecentProjectItemsModel : public QAbstractListModel
{
Q_OBJECT

Expand All @@ -60,7 +60,7 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
mutable bool exists = false;
};

explicit QgsWelcomePageItemsModel( QObject *parent = nullptr );
explicit QgsRecentProjectItemsModel( QObject *parent = nullptr );

void setRecentProjects( const QList<RecentProjectData> &recentProjects );

Expand All @@ -77,4 +77,4 @@ class QgsWelcomePageItemsModel : public QAbstractListModel
QList<RecentProjectData> mRecentProjects;
};

#endif // QGSWELCOMEPAGEITEMSMODEL_H
#endif // QGSRECENTPROJECTITEMSMODEL_H
Loading

0 comments on commit e283fb9

Please sign in to comment.