QgsExpressionContext QgsGraduatedSymbolRendererWidget::createExpressionContext() const { QgsExpressionContext expContext; expContext << QgsExpressionContextUtils::globalScope() << QgsExpressionContextUtils::projectScope( QgsProject::instance() ) << QgsExpressionContextUtils::atlasScope( nullptr ); if ( mContext.mapCanvas() ) { expContext << QgsExpressionContextUtils::mapSettingsScope( mContext.mapCanvas()->mapSettings() ) << new QgsExpressionContextScope( mContext.mapCanvas()->expressionContextScope() ); } else { expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() ); } if ( vectorLayer() ) expContext << QgsExpressionContextUtils::layerScope( vectorLayer() ); // additional scopes Q_FOREACH ( const QgsExpressionContextScope& scope, mContext.additionalExpressionContextScopes() ) { expContext.appendScope( new QgsExpressionContextScope( scope ) ); } return expContext; }
Qt::ItemFlags QgsVectorLayerAndAttributeModel::flags( const QModelIndex &index ) const { if ( index.column() == 0 ) return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; QgsVectorLayer *vl = vectorLayer( index ); if ( !vl ) return Qt::ItemIsEnabled; else return Qt::ItemIsEnabled | Qt::ItemIsEditable; }
QgsExpressionContext QgsGraduatedSymbolRendererWidget::createExpressionContext() const { QgsExpressionContext expContext; expContext << QgsExpressionContextUtils::globalScope() << QgsExpressionContextUtils::projectScope() << QgsExpressionContextUtils::atlasScope( nullptr ); if ( mapCanvas() ) { expContext << QgsExpressionContextUtils::mapSettingsScope( mapCanvas()->mapSettings() ) << new QgsExpressionContextScope( mapCanvas()->expressionContextScope() ); } else { expContext << QgsExpressionContextUtils::mapSettingsScope( QgsMapSettings() ); } if ( vectorLayer() ) expContext << QgsExpressionContextUtils::layerScope( vectorLayer() ); return expContext; }
bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const QVariant &value, int role ) { if ( index.column() == 0 && role == Qt::CheckStateRole ) { int i = 0; for ( i = 0; ; i++ ) { QModelIndex child = index.child( i, 0 ); if ( !child.isValid() ) break; setData( child, value, role ); } if ( i == 0 ) { if ( value.toInt() == Qt::Checked ) mCheckedLeafs.insert( index ); else if ( value.toInt() == Qt::Unchecked ) mCheckedLeafs.remove( index ); else Q_ASSERT( "expected checked or unchecked" ); emit dataChanged( QModelIndex(), index ); } return true; } if ( index.column() == 1 ) { if ( role != Qt::EditRole ) return false; QgsVectorLayer *vl = vectorLayer( index ); if ( vl ) { mAttributeIdx[ vl ] = value.toInt(); return true; } } return QgsLayerTreeModel::setData( index, value, role ); }
QVariant QgsVectorLayerAndAttributeModel::data( const QModelIndex& idx, int role ) const { if ( idx.column() == 0 ) { if ( role == Qt::CheckStateRole ) { if ( !idx.isValid() ) return QVariant(); if ( mCheckedLeafs.contains( idx ) ) return Qt::Checked; bool hasChecked = false, hasUnchecked = false; int n; for ( n = 0; !hasChecked || !hasUnchecked; n++ ) { QVariant v = data( idx.child( n, 0 ), role ); if ( !v.isValid() ) break; switch ( v.toInt() ) { case Qt::PartiallyChecked: // parent of partially checked child shared state return Qt::PartiallyChecked; case Qt::Checked: hasChecked = true; break; case Qt::Unchecked: hasUnchecked = true; break; } } // unchecked leaf if ( n == 0 ) return Qt::Unchecked; // both if ( hasChecked && hasUnchecked ) return Qt::PartiallyChecked; if ( hasChecked ) return Qt::Checked; Q_ASSERT( hasUnchecked ); return Qt::Unchecked; } else return QgsLayerTreeModel::data( idx, role ); } QgsVectorLayer *vl = vectorLayer( idx ); if ( vl ) { int idx = mAttributeIdx.value( vl, -1 ); if ( role == Qt::EditRole ) return idx; if ( role == Qt::DisplayRole ) { if ( vl->fields().exists( idx ) ) return vl->fields().at( idx ).name(); else return vl->name(); } if ( role == Qt::ToolTipRole ) { return tr( "Attribute containing the name of the destination layer in the DXF output." ); } } return QVariant(); }