double convertToNumber(const QStringList::const_iterator & strPtr, QStringList * lineStrList, bool & ok) { double d = -1; ok = false; if(strPtr != lineStrList->end()) d = strPtr->toDouble(&ok); return d; }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { //data defined properties double scaledWidth = 0; if ( mStrokeWidthExpression ) { scaledWidth = mStrokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } //color if ( mStrokeColorExpression ) { pen.setColor( QgsSymbolLayerV2Utils::decodeColor( mStrokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } //offset offset = mOffset; if ( mLineOffsetExpression ) { offset = mLineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } //dash dot vector if ( mDashPatternExpression ) { QVector<qreal> dashVector; QStringList dashList = mDashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" ); QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit ) / mPen.widthF() ); } pen.setDashPattern( dashVector ); } //join style if ( mJoinStyleExpression ) { QString joinStyleString = mJoinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style if ( mCapStyleExpression ) { QString capStyleString = mCapStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { if ( mDataDefinedProperties.isEmpty() ) return; // shortcut //data defined properties double scaledWidth = 0; QgsExpression* strokeWidthExpression = expression( "width" ); if ( strokeWidthExpression ) { scaledWidth = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } //color QgsExpression* strokeColorExpression = expression( "color" ); if ( strokeColorExpression ) { pen.setColor( QgsSymbolLayerV2Utils::decodeColor( strokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } //offset QgsExpression* lineOffsetExpression = expression( "offset" ); if ( lineOffsetExpression ) { offset = lineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } //dash dot vector QgsExpression* dashPatternExpression = expression( "customdash" ); if ( dashPatternExpression ) { double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); double dashWidthDiv = mPen.widthF(); if ( strokeWidthExpression ) { dashWidthDiv = pen.widthF(); scaledWidth = pen.widthF(); } //fix dash pattern width in Qt 4.8 QStringList versionSplit = QString( qVersion() ).split( "." ); if ( versionSplit.size() > 1 && versionSplit.at( 1 ).toInt() >= 8 && ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 ) { dashWidthDiv = 1.0; } QVector<qreal> dashVector; QStringList dashList = dashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" ); QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv ); } pen.setDashPattern( dashVector ); } //join style QgsExpression* joinStyleExpression = expression( "joinstyle" ); if ( joinStyleExpression ) { QString joinStyleString = joinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style QgsExpression* capStyleExpression = expression( "capstyle" ); if ( capStyleExpression ) { QString capStyleString = capStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { if ( !hasDataDefinedProperties() ) return; // shortcut //data defined properties bool hasStrokeWidthExpression = false; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) { context.setOriginalValueVariable( mWidth ); double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); hasStrokeWidthExpression = true; } //color bool ok; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( pen.color() ) ); QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant(), &ok ).toString(); if ( ok ) pen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ); } //offset if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) ) { context.setOriginalValueVariable( mOffset ); offset = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, offset ).toDouble(); } //dash dot vector if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH ) ) { double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale ); double dashWidthDiv = mPen.widthF(); if ( hasStrokeWidthExpression ) { dashWidthDiv = pen.widthF(); scaledWidth = pen.widthF(); } //fix dash pattern width in Qt 4.8 QStringList versionSplit = QString( qVersion() ).split( '.' ); if ( versionSplit.size() > 1 && versionSplit.at( 1 ).toInt() >= 8 && ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 ) { dashWidthDiv = 1.0; } QVector<qreal> dashVector; QStringList dashList = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH, context, QVariant(), &ok ).toString().split( ';' ); if ( ok ) { QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), dashIt->toDouble(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv ); } pen.setDashPattern( dashVector ); } } //line style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenStyle( pen.style() ) ); QString lineStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( lineStyleString ) ); } //join style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenJoinStyle( pen.joinStyle() ) ); QString joinStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenCapStyle( pen.capStyle() ) ); QString capStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }
bool MatchParser::parse() { QStringList::const_iterator it; for (it = m_args.constBegin(); it != m_args.constEnd(); ++it) { if (!m_validOptions.contains(*it)) { qWarning("Unknown option: \"%s\"", qPrintable(*it)); return false; } QString name = *it; PrivateOption& option = m_validOptions[name]; QStringList list; while (++it != m_args.constEnd()) { if (it->size() > 1 && it->startsWith('-')) { bool ok = false; it->toDouble(&ok); if (!ok) break; } list << *it; } --it; if (!option.duplicates && contains(name)) { qWarning("Multiple instances of option \"%s\"", qPrintable(name)); return false; } if (list.size() < option.minArgs) { if (option.maxArgs == option.minArgs) qWarning("Option \"%s\" needs %d argument(s)", qPrintable(name), option.minArgs); else qWarning("Option \"%s\" needs at least %d argument(s)", qPrintable(name), option.minArgs); return false; } if (option.maxArgs != -1 && list.size() > option.maxArgs) { qWarning("Too many arguments for option \"%s\"", qPrintable(name)); return false; } // Boolean option if (list.isEmpty()) { Option tmp = { name, QVariant(true) }; m_options.insert(option.priority, tmp); continue; } QVariant value; if (option.type == QVariant::StringList) value.setValue(list); else value.setValue(list.join(" ")); if (!value.convert(option.type)) { qWarning("Invalid value for option \"%s\": \"%s\"", qPrintable(name), qPrintable(list.join(" "))); return false; } Option tmp = { name, value }; m_options.insert(option.priority, tmp); } return true; }
QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl ) : QDialog( parent, fl ), mMapCanvas( mapCanvas ) { setupUi( this ); connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) ); connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) ); /////////////////////////////////////////////////////////// // Properties stored in map canvas's QgsMapRenderer // these ones are propagated to QgsProject by a signal QgsMapRenderer* myRender = mMapCanvas->mapRenderer(); QGis::UnitType myUnit = myRender->mapUnits(); setMapUnits( myUnit ); //see if the user wants on the fly projection enabled bool myProjectionEnabled = myRender->hasCrsTransformEnabled(); cbxProjectionEnabled->setChecked( myProjectionEnabled ); long myCRSID = myRender->destinationSrs().srsid(); QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) ); projectionSelector->setSelectedCrsId( myCRSID ); /////////////////////////////////////////////////////////// // Properties stored in QgsProject title( QgsProject::instance()->title() ); // get the manner in which the number of decimal places in the mouse // position display is set (manual or automatic) bool automaticPrecision = QgsProject::instance()->readBoolEntry( "PositionPrecision", "/Automatic" ); if ( automaticPrecision ) { radAutomatic->setChecked( true ); } else { radManual->setChecked( true ); } int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" ); spinBoxDP->setValue( dp ); //get the colour selections and set the button colour accordingly int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 ); int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 ); int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorBluePart", 0 ); QColor myColour = QColor( myRedInt, myGreenInt, myBlueInt ); pbnSelectionColour->setColor( myColour ); //get the colour for map canvas background and set button colour accordingly (default white) myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); myColour = QColor( myRedInt, myGreenInt, myBlueInt ); pbnCanvasColor->setColor( myColour ); //read the digitizing settings int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 ); if ( topologicalEditing != 0 ) { mEnableTopologicalEditingCheckBox->setCheckState( Qt::Checked ); } else { mEnableTopologicalEditingCheckBox->setCheckState( Qt::Unchecked ); } int avoidPolygonIntersections = QgsProject::instance()->readNumEntry( "Digitizing", "/AvoidPolygonIntersections", 0 ); if ( avoidPolygonIntersections != 0 ) { mAvoidIntersectionsCheckBox->setCheckState( Qt::Checked ); } else { mAvoidIntersectionsCheckBox->setCheckState( Qt::Unchecked ); } bool ok; QStringList layerIdList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingList", &ok ); QStringList enabledList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingEnabledList", &ok ); QStringList toleranceList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnappingToleranceList", &ok ); QStringList snapToList = QgsProject::instance()->readListEntry( "Digitizing", "/LayerSnapToList", &ok ); QStringList::const_iterator idIter = layerIdList.constBegin(); QStringList::const_iterator enabledIter = enabledList.constBegin(); QStringList::const_iterator tolIter = toleranceList.constBegin(); QStringList::const_iterator snapToIter = snapToList.constBegin(); QgsMapLayer* currentLayer = 0; //create the new layer entries for ( ; idIter != layerIdList.constEnd(); ++idIter, ++enabledIter, ++tolIter, ++snapToIter ) { currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *idIter ); if ( currentLayer ) { LayerEntry newEntry; newEntry.layerName = currentLayer->name(); if (( *enabledIter ) == "enabled" ) { newEntry.checked = true; } else { newEntry.checked = false; } if (( *snapToIter ) == "to_vertex" ) { newEntry.snapTo = 0; } else if (( *snapToIter ) == "to_segment" ) { newEntry.snapTo = 1; } else //to vertex and segment { newEntry.snapTo = 2; } newEntry.tolerance = tolIter->toDouble(); mSnappingLayerSettings.insert( *idIter, newEntry ); } } }