Branch data Line data Source code
1 : : /*************************************************************************** 2 : : qgslabelingenginesettings.cpp 3 : : -------------------------------------- 4 : : Date : April 2017 5 : : Copyright : (C) 2017 by Martin Dobias 6 : : Email : wonder dot sk at gmail dot com 7 : : *************************************************************************** 8 : : * * 9 : : * This program is free software; you can redistribute it and/or modify * 10 : : * it under the terms of the GNU General Public License as published by * 11 : : * the Free Software Foundation; either version 2 of the License, or * 12 : : * (at your option) any later version. * 13 : : * * 14 : : ***************************************************************************/ 15 : : 16 : : #include "qgslabelingenginesettings.h" 17 : : 18 : : #include "qgsproject.h" 19 : : #include "qgssymbollayerutils.h" 20 : : 21 : 19 : QgsLabelingEngineSettings::QgsLabelingEngineSettings() 22 : 19 : : mFlags( UsePartialCandidates ) 23 : : { 24 : 19 : } 25 : : 26 : 8 : void QgsLabelingEngineSettings::clear() 27 : : { 28 : 8 : *this = QgsLabelingEngineSettings(); 29 : 8 : } 30 : : 31 : 0 : void QgsLabelingEngineSettings::readSettingsFromProject( QgsProject *prj ) 32 : : { 33 : 0 : bool saved = false; 34 : 0 : mSearchMethod = static_cast< Search >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( Chain ), &saved ) ); 35 : 0 : mMaxLineCandidatesPerCm = prj->readDoubleEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLinePerCM" ), 5, &saved ); 36 : 0 : mMaxPolygonCandidatesPerCmSquared = prj->readDoubleEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygonPerCM" ), 2.5, &saved ); 37 : : 38 : 0 : mFlags = Flags(); 39 : 0 : if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), false, &saved ) ) mFlags |= DrawCandidates; 40 : 0 : if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), false, &saved ) ) mFlags |= DrawLabelRectOnly; 41 : 0 : if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), false, &saved ) ) mFlags |= UseAllLabels; 42 : 0 : if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), true, &saved ) ) mFlags |= UsePartialCandidates; 43 : 0 : if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawUnplaced" ), false, &saved ) ) mFlags |= DrawUnplacedLabels; 44 : : 45 : 0 : mDefaultTextRenderFormat = QgsRenderContext::TextFormatAlwaysOutlines; 46 : : // if users have disabled the older PAL "DrawOutlineLabels" setting, respect that 47 : 0 : if ( !prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true ) ) 48 : 0 : mDefaultTextRenderFormat = QgsRenderContext::TextFormatAlwaysText; 49 : : // otherwise, prefer the new setting 50 : 0 : const int projectTextFormat = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/TextFormat" ), -1 ); 51 : 0 : if ( projectTextFormat >= 0 ) 52 : 0 : mDefaultTextRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( projectTextFormat ); 53 : : 54 : 0 : mUnplacedLabelColor = QgsSymbolLayerUtils::decodeColor( prj->readEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QStringLiteral( "#ff0000" ) ) ); 55 : : 56 : 0 : mPlacementVersion = static_cast< PlacementEngineVersion >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/PlacementEngineVersion" ), static_cast< int >( PlacementEngineVersion1 ) ) ); 57 : 0 : } 58 : : 59 : 0 : void QgsLabelingEngineSettings::writeSettingsToProject( QgsProject *project ) 60 : : { 61 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( mSearchMethod ) ); 62 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLinePerCM" ), mMaxLineCandidatesPerCm ); 63 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygonPerCM" ), mMaxPolygonCandidatesPerCmSquared ); 64 : : 65 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), mFlags.testFlag( DrawCandidates ) ); 66 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), mFlags.testFlag( DrawLabelRectOnly ) ); 67 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawUnplaced" ), mFlags.testFlag( DrawUnplacedLabels ) ); 68 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), mFlags.testFlag( UseAllLabels ) ); 69 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), mFlags.testFlag( UsePartialCandidates ) ); 70 : : 71 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/TextFormat" ), static_cast< int >( mDefaultTextRenderFormat ) ); 72 : : 73 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QgsSymbolLayerUtils::encodeColor( mUnplacedLabelColor ) ); 74 : : 75 : 0 : project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/PlacementEngineVersion" ), mPlacementVersion ); 76 : 0 : } 77 : : 78 : 0 : QColor QgsLabelingEngineSettings::unplacedLabelColor() const 79 : : { 80 : 0 : return mUnplacedLabelColor; 81 : : } 82 : : 83 : 0 : void QgsLabelingEngineSettings::setUnplacedLabelColor( const QColor &unplacedLabelColor ) 84 : : { 85 : 0 : mUnplacedLabelColor = unplacedLabelColor; 86 : 0 : } 87 : : 88 : 0 : QgsLabelingEngineSettings::PlacementEngineVersion QgsLabelingEngineSettings::placementVersion() const 89 : : { 90 : 0 : return mPlacementVersion; 91 : : } 92 : : 93 : 0 : void QgsLabelingEngineSettings::setPlacementVersion( PlacementEngineVersion placementVersion ) 94 : : { 95 : 0 : mPlacementVersion = placementVersion; 96 : 0 : } 97 : : 98 : :