Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions app/attributes/attributepreviewcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ AttributePreviewModel::~AttributePreviewModel() = default;
int AttributePreviewModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return mItems.size();
return static_cast<int>( mItems.size() );
}

QVariant AttributePreviewModel::data( const QModelIndex &index, int role ) const
QVariant AttributePreviewModel::data( const QModelIndex &index, const int role ) const
{
if ( !index.isValid() )
return QVariant();
return {};

const int row = index.row();
if ( row < 0 || row >= mItems.size() )
return QVariant();
return {};

switch ( role )
{
Expand All @@ -57,24 +57,24 @@ QVariant AttributePreviewModel::data( const QModelIndex &index, int role ) const
case AttributePreviewModel::Value:
return mItems.at( row ).second;
default:
return QVariant();
return {};
}
}

QVector<QPair<QString, QString>> AttributePreviewController::mapTipFields( )
{
if ( !mFeatureLayerPair.layer() || !mFeatureLayerPair.feature().isValid() )
return QVector<QPair<QString, QString>> ();
return {};

QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate();
const QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().replace( QStringLiteral( "\r" ), QString() );
QVector<QPair<QString, QString>> lst;
const QgsFields fields = mFeatureLayerPair.layer()->fields();

if ( mapTip.isEmpty() )
{
// user has not provided any map tip - let's use first two fields to show
// at least something.
QString featureTitleExpression = mFeatureLayerPair.layer()->displayExpression();
const QString featureTitleExpression = mFeatureLayerPair.layer()->displayExpression();
for ( const QgsField &field : fields )
{
if ( featureTitleExpression != field.name() )
Expand All @@ -97,7 +97,7 @@ QVector<QPair<QString, QString>> AttributePreviewController::mapTipFields( )
QStringList lines = mapTip.split( '\n' );
for ( int i = 1; i < lines.count(); ++i ) // starting from index to avoid first line with "# fields"
{
int index = fields.indexFromName( lines[i] );
const int index = fields.indexFromName( lines[i] );
if ( index >= 0 )
{
const QString val = mFeatureLayerPair.feature().attribute( index ).toString();
Expand All @@ -119,7 +119,7 @@ QString AttributePreviewController::mapTipImage()
{
QgsExpressionContext context( globalProjectLayerScopes( mFeatureLayerPair.layer() ) );
context.setFeature( mFeatureLayerPair.feature() );
QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().remove( "# image\n" ); // first line is "# image"
const QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().remove( "# image\n" ); // first line is "# image"
return QgsExpression::replaceExpressionText( mapTip, &context );
}

Expand Down Expand Up @@ -156,7 +156,7 @@ QString AttributePreviewController::featureTitle( )
return title;
}

QList<QgsExpressionContextScope *> AttributePreviewController::globalProjectLayerScopes( QgsMapLayer *layer )
QList<QgsExpressionContextScope *> AttributePreviewController::globalProjectLayerScopes( const QgsMapLayer *layer )
{
// can't use QgsExpressionContextUtils::globalProjectLayerScopes() because it uses QgsProject::instance()
QList<QgsExpressionContextScope *> scopes;
Expand All @@ -173,7 +173,7 @@ AttributePreviewModel *AttributePreviewController::fieldModel() const

AttributePreviewController::AttributePreviewController( QObject *parent )
: QObject( parent )
, mFieldModel( new AttributePreviewModel() )
, mFieldModel( std::make_unique<AttributePreviewModel>() )
{
}

Expand Down Expand Up @@ -220,15 +220,15 @@ void AttributePreviewController::recalculate()
mPhoto.clear();
mTitle.clear();
mType = AttributePreviewController::Empty;
mFieldModel.reset( new AttributePreviewModel() );
mFieldModel = std::make_unique<AttributePreviewModel>();

if ( !mFeatureLayerPair.layer() || !mFeatureLayerPair.feature().isValid() )
return;

mTitle = featureTitle();

// Stripping extra CR char to unify Windows lines with Unix.
QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().replace( QStringLiteral( "\r" ), QStringLiteral( "" ) );
const QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().replace( QStringLiteral( "\r" ), QString() );
if ( mapTip.startsWith( "# image\n" ) )
{
mType = AttributePreviewController::Photo;
Expand All @@ -240,7 +240,7 @@ void AttributePreviewController::recalculate()
if ( !items.empty() )
{
mType = AttributePreviewController::Fields;
mFieldModel.reset( new AttributePreviewModel( items ) );
mFieldModel = std::make_unique<AttributePreviewModel>( items );
}
}
else
Expand Down
17 changes: 7 additions & 10 deletions app/attributes/attributepreviewcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
#define ATTRIBUTEPREVIEWCONTROLLER_H

#include <QAbstractListModel>
#include <QPair>
#include <QVector>
#include <QString>

#include "qgsproject.h"
#include "featurelayerpair.h"
#include "inputconfig.h"

class QgsExpressionContextScope;
class QgsVectorLayer;
Expand Down Expand Up @@ -74,18 +71,18 @@ class AttributePreviewModel : public QAbstractListModel
* => PreviewType.Fields
* => not supported by QGIS
*
* 2. qgis' mapTip constains "# fields", following by one
* 2. qgis' mapTip contains "# fields", following by one
* "display name" per line. Only first mLimit
* fields are shown.
* => PreviewType.Fields
* => not supported by QGIS
*
* 3. qgis' mapTip constains "# image", following by relative
* 3. qgis' mapTip contains "# image", following by relative
* path to the image
* => PreviewType.Image
* => not supported by QGIS
*
* 4. qgis' mapTip constains some (html) text
* 4. qgis' mapTip contains some (html) text
* => PreviewType.Html
* => supported by QGIS
*
Expand All @@ -101,7 +98,7 @@ class AttributePreviewController: public QObject
Q_PROPERTY( FeatureLayerPair featureLayerPair READ featureLayerPair WRITE setFeatureLayerPair NOTIFY featureLayerPairChanged )
Q_PROPERTY( QgsProject *project READ project WRITE setProject NOTIFY projectChanged )

// never nullprt
// never nullptr
Q_PROPERTY( AttributePreviewModel *fieldModel READ fieldModel NOTIFY featureLayerPairChanged )
Q_PROPERTY( QString html READ html NOTIFY featureLayerPairChanged )
Q_PROPERTY( QString photo READ photo NOTIFY featureLayerPairChanged )
Expand Down Expand Up @@ -139,10 +136,10 @@ class AttributePreviewController: public QObject
void projectChanged();

private:
QList<QgsExpressionContextScope *> globalProjectLayerScopes( QgsMapLayer *layer );
QList<QgsExpressionContextScope *> globalProjectLayerScopes( const QgsMapLayer *layer );
void recalculate();
QString mapTipImage();
QVector<QPair<QString, QString> > mapTipFields();
QVector<QPair<QString, QString>> mapTipFields();
QString mapTipHtml();
QString featureTitle();

Expand All @@ -156,4 +153,4 @@ class AttributePreviewController: public QObject
const int mLimit = 3;
};

#endif // ATTRIBUTEPREVIEWMODEL_H
#endif // ATTRIBUTEPREVIEWCONTROLLER_H
Loading