diff --git a/src/app/qgssettingstree.cpp b/src/app/qgssettingstree.cpp index be9a1b420717..2e0d83968086 100644 --- a/src/app/qgssettingstree.cpp +++ b/src/app/qgssettingstree.cpp @@ -60,11 +60,9 @@ QgsSettingsTree::QgsSettingsTree( QWidget *parent ) QStringList labels; labels << tr( "Setting" ) << tr( "Type" ) << tr( "Value" ) << tr( "Description" ); setHeaderLabels( labels ); - // header()->setResizeMode( 0, QHeaderView::Stretch ); - // header()->setResizeMode( 2, QHeaderView::Stretch ); - header()->resizeSection( 0, 250 ); - header()->resizeSection( 1, 100 ); - header()->resizeSection( 2, 250 ); + header()->resizeSection( ColumnSettings, 250 ); + header()->resizeSection( ColumnType, 100 ); + header()->resizeSection( ColumnValue, 250 ); mRefreshTimer.setInterval( 2000 ); @@ -170,7 +168,7 @@ void QgsSettingsTree::updateSetting( QTreeWidgetItem *item ) if ( key.isNull() ) return; - mSettings->setValue( key, item->data( 2, Qt::UserRole ) ); + mSettings->setValue( key, item->data( ColumnValue, Qt::UserRole ) ); if ( mAutoRefresh ) refresh(); } @@ -181,9 +179,9 @@ void QgsSettingsTree::showContextMenu( QPoint pos ) if ( !item ) return; - Type itemType = item->data( 0, TypeRole ).value< Type >(); - const QString itemText = item->data( 0, Qt::DisplayRole ).toString(); - const QString itemPath = item->data( 0, PathRole ).toString(); + Type itemType = item->data( ColumnSettings, TypeRole ).value< Type >(); + const QString itemText = item->data( ColumnSettings, Qt::DisplayRole ).toString(); + const QString itemPath = item->data( ColumnSettings, PathRole ).toString(); mContextMenu->clear(); switch ( itemType ) @@ -242,16 +240,16 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) if ( childIndex != -1 ) { child = childAt( parent, childIndex ); - child->setText( 1, QString() ); - child->setText( 2, QString() ); - child->setData( 2, Qt::UserRole, QVariant() ); + child->setText( ColumnType, QString() ); + child->setText( ColumnValue, QString() ); + child->setData( ColumnValue, Qt::UserRole, QVariant() ); moveItemForward( parent, childIndex, dividerIndex ); } else { child = createItem( group, parent, dividerIndex, true ); } - child->setIcon( 0, mGroupIcon ); + child->setIcon( ColumnSettings, mGroupIcon ); ++dividerIndex; mSettings->beginGroup( group ); @@ -278,7 +276,7 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) { child = createItem( key, parent, dividerIndex, false ); } - child->setIcon( 0, mKeyIcon ); + child->setIcon( ColumnSettings, mKeyIcon ); ++dividerIndex; } else @@ -289,14 +287,14 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent ) QVariant value = mSettings->value( key ); if ( value.type() == QVariant::Invalid ) { - child->setText( 1, QStringLiteral( "Invalid" ) ); + child->setText( ColumnType, QStringLiteral( "Invalid" ) ); } else { - child->setText( 1, QVariant::typeToName( QgsVariantDelegate::type( value ) ) ); + child->setText( ColumnType, QVariant::typeToName( QgsVariantDelegate::type( value ) ) ); } - child->setText( 2, QgsVariantDelegate::displayText( value ) ); - child->setData( 2, Qt::UserRole, value ); + child->setText( ColumnValue, QgsVariantDelegate::displayText( value ) ); + child->setData( ColumnValue, Qt::UserRole, value ); } while ( dividerIndex < childCount( parent ) ) @@ -316,21 +314,24 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, else item = new QTreeWidgetItem( this, after ); - item->setText( 0, text ); + item->setText( ColumnSettings, text ); if ( !isGroup ) item->setFlags( item->flags() | Qt::ItemIsEditable ); - item->setData( 0, TypeRole, isGroup ? Group : Setting ); + item->setData( ColumnSettings, TypeRole, isGroup ? Group : Setting ); - QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text; - item->setData( 0, PathRole, completeSettingsPath ); + const QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text; + item->setData( ColumnSettings, PathRole, completeSettingsPath ); // If settings registered add description if ( !isGroup ) { const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->getSettingsEntry( completeSettingsPath, true ); - if ( settingsEntry != nullptr ) - item->setText( 3, settingsEntry->description() ); + if ( settingsEntry ) + { + item->setText( ColumnDescription, settingsEntry->description() ); + item->setToolTip( ColumnDescription, settingsEntry->description() ); + } } QString key = itemKey( item ); @@ -339,9 +340,10 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, { QgsDebugMsgLevel( QStringLiteral( "contains!!!!" ), 4 ); QStringList values = mSettingsMap[ key ]; - item->setText( 3, values.at( 0 ) ); - item->setToolTip( 0, values.at( 1 ) ); - item->setToolTip( 2, values.at( 1 ) ); + item->setText( ColumnDescription, values.at( 0 ) ); + item->setToolTip( ColumnDescription, values.at( 0 ) ); + item->setToolTip( ColumnSettings, values.at( 1 ) ); + item->setToolTip( ColumnValue, values.at( 1 ) ); } return item; @@ -352,11 +354,11 @@ QString QgsSettingsTree::itemKey( QTreeWidgetItem *item ) if ( ! item ) return QString(); - QString key = item->text( 0 ); + QString key = item->text( ColumnSettings ); QTreeWidgetItem *ancestor = item->parent(); while ( ancestor ) { - key.prepend( ancestor->text( 0 ) + '/' ); + key.prepend( ancestor->text( ColumnSettings ) + '/' ); ancestor = ancestor->parent(); } @@ -384,7 +386,7 @@ int QgsSettingsTree::findChild( QTreeWidgetItem *parent, const QString &text, { for ( int i = startIndex; i < childCount( parent ); ++i ) { - if ( childAt( parent, i )->text( 0 ) == text ) + if ( childAt( parent, i )->text( ColumnSettings ) == text ) return i; } return -1; diff --git a/src/app/qgssettingstree.h b/src/app/qgssettingstree.h index 7dbc1c06b127..4253b7a73627 100644 --- a/src/app/qgssettingstree.h +++ b/src/app/qgssettingstree.h @@ -89,6 +89,15 @@ class QgsSettingsTree : public QTreeWidget void showContextMenu( QPoint pos ); private: + + enum Columns + { + ColumnSettings = 0, + ColumnType, + ColumnValue, + ColumnDescription + }; + void updateChildItems( QTreeWidgetItem *parent ); QTreeWidgetItem *createItem( const QString &text, QTreeWidgetItem *parent, int index, bool isGroup ); diff --git a/src/core/settings/qgssettingsentry.cpp b/src/core/settings/qgssettingsentry.cpp index 8e78b2f9f4f9..9d8a6fa8441c 100644 --- a/src/core/settings/qgssettingsentry.cpp +++ b/src/core/settings/qgssettingsentry.cpp @@ -77,7 +77,7 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const for ( int i = 0; i < dynamicKeyPartList.size(); i++ ) { - completeKey.replace( QStringLiteral( "%%1" ).arg( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); + completeKey.replace( QStringLiteral( "%" ).append( QString::number( i + 1 ) ), dynamicKeyPartList.at( i ) ); } } return completeKey; @@ -118,8 +118,8 @@ bool QgsSettingsEntryBase::keyIsValid( const QString &key ) const return completeKeyToCheck == prefixedSettingsKey; QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( QStringLiteral( "%\\d+" ) ), QStringLiteral( ".*" ) ) ); - QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKeyToCheck ); - return regularExpresisonMatch.hasMatch(); + QRegularExpressionMatch regularExpressionMatch = regularExpression.match( completeKeyToCheck ); + return regularExpressionMatch.hasMatch(); } QString QgsSettingsEntryBase::definitionKey() const @@ -137,7 +137,7 @@ QString QgsSettingsEntryBase::definitionKey() const bool QgsSettingsEntryBase::hasDynamicKey() const { - static const QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) ); + const thread_local QRegularExpression regularExpression( QStringLiteral( "%\\d+" ) ); return mKey.contains( regularExpression ); }