diff --git a/app/attributes/attributepreviewcontroller.cpp b/app/attributes/attributepreviewcontroller.cpp index 6c328afc0..5d2942cc3 100644 --- a/app/attributes/attributepreviewcontroller.cpp +++ b/app/attributes/attributepreviewcontroller.cpp @@ -38,17 +38,17 @@ AttributePreviewModel::~AttributePreviewModel() = default; int AttributePreviewModel::rowCount( const QModelIndex &parent ) const { Q_UNUSED( parent ) - return mItems.size(); + return static_cast( 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 ) { @@ -57,16 +57,16 @@ QVariant AttributePreviewModel::data( const QModelIndex &index, int role ) const case AttributePreviewModel::Value: return mItems.at( row ).second; default: - return QVariant(); + return {}; } } QVector> AttributePreviewController::mapTipFields( ) { if ( !mFeatureLayerPair.layer() || !mFeatureLayerPair.feature().isValid() ) - return QVector> (); + return {}; - QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate(); + const QString mapTip = mFeatureLayerPair.layer()->mapTipTemplate().replace( QStringLiteral( "\r" ), QString() ); QVector> lst; const QgsFields fields = mFeatureLayerPair.layer()->fields(); @@ -74,7 +74,7 @@ QVector> AttributePreviewController::mapTipFields( ) { // 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() ) @@ -97,7 +97,7 @@ QVector> 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(); @@ -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 ); } @@ -156,7 +156,7 @@ QString AttributePreviewController::featureTitle( ) return title; } -QList AttributePreviewController::globalProjectLayerScopes( QgsMapLayer *layer ) +QList AttributePreviewController::globalProjectLayerScopes( const QgsMapLayer *layer ) { // can't use QgsExpressionContextUtils::globalProjectLayerScopes() because it uses QgsProject::instance() QList scopes; @@ -173,7 +173,7 @@ AttributePreviewModel *AttributePreviewController::fieldModel() const AttributePreviewController::AttributePreviewController( QObject *parent ) : QObject( parent ) - , mFieldModel( new AttributePreviewModel() ) + , mFieldModel( std::make_unique() ) { } @@ -220,7 +220,7 @@ void AttributePreviewController::recalculate() mPhoto.clear(); mTitle.clear(); mType = AttributePreviewController::Empty; - mFieldModel.reset( new AttributePreviewModel() ); + mFieldModel = std::make_unique(); if ( !mFeatureLayerPair.layer() || !mFeatureLayerPair.feature().isValid() ) return; @@ -228,7 +228,7 @@ void AttributePreviewController::recalculate() 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; @@ -240,7 +240,7 @@ void AttributePreviewController::recalculate() if ( !items.empty() ) { mType = AttributePreviewController::Fields; - mFieldModel.reset( new AttributePreviewModel( items ) ); + mFieldModel = std::make_unique( items ); } } else diff --git a/app/attributes/attributepreviewcontroller.h b/app/attributes/attributepreviewcontroller.h index 67634c93a..c345e6e8f 100644 --- a/app/attributes/attributepreviewcontroller.h +++ b/app/attributes/attributepreviewcontroller.h @@ -16,13 +16,10 @@ #define ATTRIBUTEPREVIEWCONTROLLER_H #include -#include -#include #include #include "qgsproject.h" #include "featurelayerpair.h" -#include "inputconfig.h" class QgsExpressionContextScope; class QgsVectorLayer; @@ -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 * @@ -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 ) @@ -139,10 +136,10 @@ class AttributePreviewController: public QObject void projectChanged(); private: - QList globalProjectLayerScopes( QgsMapLayer *layer ); + QList globalProjectLayerScopes( const QgsMapLayer *layer ); void recalculate(); QString mapTipImage(); - QVector > mapTipFields(); + QVector> mapTipFields(); QString mapTipHtml(); QString featureTitle(); @@ -156,4 +153,4 @@ class AttributePreviewController: public QObject const int mLimit = 3; }; -#endif // ATTRIBUTEPREVIEWMODEL_H +#endif // ATTRIBUTEPREVIEWCONTROLLER_H