snapping dialog: block signals when reloading snapping options

QgsProject: also apply default when property is not available and not only if
an existing one is invalid

fixes #12192
This commit is contained in:
Juergen E. Fischer 2015-02-15 12:50:06 +01:00
parent ccdf452ef4
commit e2e23f0c8e
3 changed files with 178 additions and 304 deletions

View File

@ -132,36 +132,6 @@ class QgsProject : QObject
bool write();
//@}
/// syntactic sugar for property lists
// DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
// DEPRECATED typedef QValueList< PropertyValue > Properties;
/** extra properties, typically added by plug-ins
This allows for extra properties to be associated with projects. Think
of it as a registry bound to a project.
Properties are arbitrary values keyed by a name and associated with a
scope. The scope would presumably refer to your plug-in.
E.g., "openmodeller".
@note
E.g., open modeller might use:
<code>"QgsProject::instance()->properties("openmodeller")["foo"]</code>.
@todo "properties" is, overall, a good name; but that might imply that
the qgis specific state properites are different since they aren't
accessible here. Actually, what if we make "qgis" yet another
scope that stores its state in the properties list? E.g.,
QgsProject::instance()->properties()["qgis"]?
*/
// DEPRECATED Properties & properties( QString const & scope );
/**
removes all project properties

View File

@ -133,15 +133,21 @@ void QgsSnappingDialog::reload()
idx = 0;
else // off
idx = 3;
mDefaultSnapToComboBox->blockSignals( true );
mDefaultSnapToComboBox->setCurrentIndex( idx );
mDefaultSnapToComboBox->blockSignals( false );
double tolerance = settings.value( "/qgis/digitizing/default_snapping_tolerance", 0 ).toDouble();
tolerance = QgsProject::instance()->readDoubleEntry( "Digitizing", "/DefaultSnapTolerance", tolerance );
mDefaultSnappingToleranceSpinBox->blockSignals( true );
mDefaultSnappingToleranceSpinBox->setValue( tolerance );
mDefaultSnappingToleranceSpinBox->blockSignals( false );
int unit = settings.value( "/qgis/digitizing/default_snapping_tolerance_unit", QgsTolerance::ProjectUnits ).toInt();
unit = QgsProject::instance()->readNumEntry( "Digitizing", "/DefaultSnapToleranceUnit", unit );
mDefaultSnappingToleranceComboBox->blockSignals( true );
mDefaultSnappingToleranceComboBox->setCurrentIndex( unit == QgsTolerance::Pixels ? 1 : 0 );
mDefaultSnappingToleranceComboBox->blockSignals( false );
mLayerTreeWidget->clear();
@ -202,7 +208,6 @@ void QgsSnappingDialog::closeEvent( QCloseEvent* event )
}
}
void QgsSnappingDialog::apply()
{
QString snapMode;
@ -492,6 +497,7 @@ void QgsSnappingDialog::setIntersectionSnappingState()
void QgsSnappingDialog::setSnappingMode()
{
mSnapModeComboBox->blockSignals( true );
QString snapMode = QgsProject::instance()->readEntry( "Digitizing", "/SnappingMode" );
if ( snapMode == "current_layer" )
mSnapModeComboBox->setCurrentIndex( 0 );
@ -499,5 +505,5 @@ void QgsSnappingDialog::setSnappingMode()
mSnapModeComboBox->setCurrentIndex( 1 );
else // "advanced" or empty (backward compatibility)
mSnapModeComboBox->setCurrentIndex( 2 );
mSnapModeComboBox->blockSignals( false );
}

View File

@ -57,10 +57,6 @@ QgsProject *QgsProject::theProject_ = 0;
static
QStringList makeKeyTokens_( QString const &scope, QString const &key )
{
// XXX - debugger probes
//const char * scope_str = scope.toLocal8Bit().data();
//const char * key_str = key.toLocal8Bit().data();
QStringList keyTokens = QStringList( scope );
keyTokens += key.split( '/', QString::SkipEmptyParts );
@ -83,16 +79,16 @@ QStringList makeKeyTokens_( QString const &scope, QString const &key )
@return null if not found, otherwise located Property
*/
static
QgsProperty * findKey_( QString const & scope,
QString const & key,
QgsPropertyKey & rootProperty )
QgsProperty *findKey_( QString const &scope,
QString const &key,
QgsPropertyKey &rootProperty )
{
QgsPropertyKey * currentProperty = &rootProperty;
QgsProperty * nextProperty; // link to next property down hiearchy
QgsPropertyKey *currentProperty = &rootProperty;
QgsProperty *nextProperty; // link to next property down hiearchy
QStringList keySequence = makeKeyTokens_( scope, key );
while ( ! keySequence.isEmpty() )
while ( !keySequence.isEmpty() )
{
// if the current head of the sequence list matches the property name,
// then traverse down the property hierarchy
@ -101,17 +97,16 @@ QgsProperty * findKey_( QString const & scope,
// remove front key since we're traversing down a level
keySequence.pop_front();
// if we have only one key name left, then return the key found
if ( 1 == keySequence.count() )
{
// if we have only one key name left, then return the key found
return currentProperty->find( keySequence.front() );
}
// if we're out of keys then the current property is the one we
// want; i.e., we're in the rate case of being at the top-most
// property node
else if ( keySequence.isEmpty() )
{
// if we're out of keys then the current property is the one we
// want; i.e., we're in the rate case of being at the top-most
// property node
return currentProperty;
}
else if (( nextProperty = currentProperty->find( keySequence.first() ) ) )
@ -120,31 +115,34 @@ QgsProperty * findKey_( QString const & scope,
{
currentProperty = dynamic_cast<QgsPropertyKey*>( nextProperty );
}
// it may be that this may be one of several property value
// nodes keyed by QDict string; if this is the last remaining
// key token and the next property is a value node, then
// that's the situation, so return the currentProperty
else if ( nextProperty->isValue() && ( 1 == keySequence.count() ) )
else if ( nextProperty->isValue() && 1 == keySequence.count() )
{
// it may be that this may be one of several property value
// nodes keyed by QDict string; if this is the last remaining
// key token and the next property is a value node, then
// that's the situation, so return the currentProperty
return currentProperty;
}
else // QgsPropertyValue not Key, so return null
else
{
return 0x0;
// QgsPropertyValue not Key, so return null
return 0;
}
}
else // if the next key down isn't found
{ // then the overall key sequence doesn't exist
return 0x0;
else
{
// if the next key down isn't found
// then the overall key sequence doesn't exist
return 0;
}
}
else
{
return 0x0;
return 0;
}
}
return 0x0;
return 0;
} // findKey_
@ -157,17 +155,16 @@ QgsProperty * findKey_( QString const & scope,
@param value the value associated with the key
*/
static
QgsProperty * addKey_( QString const & scope,
QString const & key,
QgsPropertyKey * rootProperty,
QVariant value )
QgsProperty *addKey_( QString const &scope,
QString const &key,
QgsPropertyKey *rootProperty,
QVariant value )
{
QStringList keySequence = makeKeyTokens_( scope, key );
// cursor through property key/value hierarchy
QgsPropertyKey * currentProperty = rootProperty;
QgsProperty * newProperty; // link to next property down hiearchy
QgsPropertyKey *currentProperty = rootProperty;
QgsProperty *newProperty; // link to next property down hiearchy
while ( ! keySequence.isEmpty() )
{
@ -203,7 +200,7 @@ QgsProperty * addKey_( QString const & scope,
}
else // QgsPropertyValue not Key, so return null
{
return 0x0;
return 0;
}
}
else // the next subkey doesn't exist, so add it
@ -219,25 +216,25 @@ QgsProperty * addKey_( QString const & scope,
}
else
{
return 0x0;
return 0;
}
}
return 0x0;
return 0;
} // addKey_
static
void removeKey_( QString const & scope,
QString const & key,
QgsPropertyKey & rootProperty )
void removeKey_( QString const &scope,
QString const &key,
QgsPropertyKey &rootProperty )
{
QgsPropertyKey * currentProperty = &rootProperty;
QgsPropertyKey *currentProperty = &rootProperty;
QgsProperty * nextProperty = NULL; // link to next property down hiearchy
QgsPropertyKey * previousQgsPropertyKey = NULL; // link to previous property up hiearchy
QgsProperty *nextProperty = 0; // link to next property down hiearchy
QgsPropertyKey *previousQgsPropertyKey = 0; // link to previous property up hiearchy
QStringList keySequence = makeKeyTokens_( scope, key );
@ -294,17 +291,10 @@ void removeKey_( QString const & scope,
struct QgsProject::Imp
{
/// current physical project file
QFile file;
/// property hierarchy
QgsPropertyKey properties_;
/// project title
QString title;
/// true if project has been modified since it has been read or saved
bool dirty;
QFile file; // current physical project file
QgsPropertyKey properties_; // property hierarchy
QString title; // project title
bool dirty; // project has been modified since it has been read or saved
Imp()
: title()
@ -319,7 +309,7 @@ struct QgsProject::Imp
*/
void clear()
{
//QgsDebugMsg( "Clearing project properties Impl->clear();" );
// QgsDebugMsg( "Clearing project properties Impl->clear();" );
file.setFileName( QString() );
properties_.clearKeys();
@ -375,13 +365,13 @@ void QgsProject::title( QString const &title )
dirty( true );
} // void QgsProject::title
void QgsProject::setTitle( const QString& t )
void QgsProject::setTitle( const QString &t )
{
title( t );
}
QString const & QgsProject::title() const
QString const &QgsProject::title() const
{
return imp_->title;
} // QgsProject::title() const
@ -410,7 +400,7 @@ void QgsProject::setFileName( QString const &name )
imp_->file.setFileName( name );
dirty( true );
} // void QgsProject::setFileName( QString const & name )
} // void QgsProject::setFileName( QString const &name )
@ -436,19 +426,14 @@ void QgsProject::clear()
setDirty( false );
}
/// basically a debugging tool to dump property list values
static void dump_( QgsPropertyKey const & topQgsPropertyKey )
// basically a debugging tool to dump property list values
static void dump_( QgsPropertyKey const &topQgsPropertyKey )
{
QgsDebugMsg( "current properties:" );
topQgsPropertyKey.dump();
} // dump_
/**
Restore any optional properties found in "doc" to "properties".
@ -481,7 +466,7 @@ scope. "layers" is a list containing three string values.
*/
static
void
_getProperties( QDomDocument const &doc, QgsPropertyKey & project_properties )
_getProperties( QDomDocument const &doc, QgsPropertyKey &project_properties )
{
QDomNodeList properties = doc.elementsByTagName( "properties" );
@ -495,8 +480,7 @@ _getProperties( QDomDocument const &doc, QgsPropertyKey & project_properties )
return;
}
// item(0) because there should only be ONE
// "properties" node
// item(0) because there should only be ONE "properties" node
QDomNodeList scopes = properties.item( 0 ).childNodes();
if ( scopes.count() < 1 )
@ -511,45 +495,6 @@ _getProperties( QDomDocument const &doc, QgsPropertyKey & project_properties )
{
QgsDebugMsg( "Project_properties.readXML() failed" );
}
#if 0
// DEPRECATED as functionality has been shoved down to QgsProperyKey::readXML()
size_t i = 0;
while ( i < scopes.count() )
{
QDomNode curr_scope_node = scopes.item( i );
qDebug( "found %d property node(s) for scope %s",
curr_scope_node.childNodes().count(),
curr_scope_node.nodeName().utf8().constData() );
QString key( curr_scope_node.nodeName() );
QgsPropertyKey * currentKey =
dynamic_cast<QgsPropertyKey*>( project_properties.find( key ) );
if ( ! currentKey )
{
// if the property key doesn't yet exist, create an empty instance
// of that key
currentKey = project_properties.addKey( key );
if ( ! currentKey )
{
qDebug( "%s:%d unable to add key", __FILE__, __LINE__ );
}
}
if ( ! currentKey->readXML( curr_scope_node ) )
{
qDebug( "%s:%d unable to read XML for property %s", __FILE__, __LINE__,
curr_scope_node.nodeName().utf8().constData() );
}
++i;
}
#endif
} // _getProperties
@ -566,7 +511,7 @@ _getProperties( QDomDocument const &doc, QgsPropertyKey & project_properties )
@todo XXX we should go with the attribute xor title, not both.
*/
static void _getTitle( QDomDocument const &doc, QString & title )
static void _getTitle( QDomDocument const &doc, QString &title )
{
QDomNodeList nl = doc.elementsByTagName( "title" );
@ -678,10 +623,6 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
QDomNodeList nl = doc.elementsByTagName( "maplayer" );
// XXX what is this used for? QString layerCount( QString::number(nl.count()) );
QString wk;
QList<QDomNode> brokenNodes; // a list of Dom nodes corresponding to layers
// that we were unable to load; this could be
// because the layers were removed or
@ -703,8 +644,8 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
emit layerLoaded( 0, nl.count() );
//Collect vector layers with joins.
//They need to refresh join caches and symbology infos after all layers are loaded
// Collect vector layers with joins.
// They need to refresh join caches and symbology infos after all layers are loaded
QList< QPair< QgsVectorLayer*, QDomElement > > vLayerList;
for ( int i = 0; i < nl.count(); i++ )
@ -731,8 +672,8 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
emit layerLoaded( i + 1, nl.count() );
}
//Update field map of layers with joins and create join caches if necessary
//Needs to be done here once all dependent layers are loaded
// Update field map of layers with joins and create join caches if necessary
// Needs to be done here once all dependent layers are loaded
QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin();
for ( ; vIt != vLayerList.end(); ++vIt )
{
@ -741,14 +682,13 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
}
return qMakePair( returnStatus, brokenNodes );
} // _getMapLayers
bool QgsProject::addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList )
bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > > &vectorLayerList )
{
QString type = layerElem.attribute( "type" );
QgsDebugMsg( "Layer type is " + type );
QgsMapLayer *mapLayer = NULL;
QgsMapLayer *mapLayer = 0;
if ( type == "vector" )
{
@ -781,7 +721,7 @@ bool QgsProject::addLayer( const QDomElement& layerElem, QList<QDomNode>& broken
QList<QgsMapLayer *> myLayers;
myLayers << mapLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myLayers );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
if ( vLayer && vLayer->vectorJoins().size() > 0 )
{
vectorLayerList.push_back( qMakePair( vLayer, layerElem ) );
@ -876,18 +816,10 @@ bool QgsProject::read()
emit oldProjectVersionWarning( fileVersion.text() );
QgsDebugMsg( "Emitting oldProjectVersionWarning(oldVersion)." );
// Commented out by Tim - overly verbose on console
// projectFile.dump();
projectFile.updateRevision( thisVersion );
// Commented out by Tim - overly verbose on console
// projectFile.dump();
}
// start new project, just keep the file name
QString fileName = imp_->file.fileName();
clear();
imp_->file.setFileName( fileName );
@ -962,24 +894,24 @@ bool QgsProject::read()
} // QgsProject::read
void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup* group )
void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
{
foreach ( QgsLayerTreeNode* child, group->children() )
foreach ( QgsLayerTreeNode *child, group->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
QgsLayerTreeGroup* childGroup = QgsLayerTree::toGroup( child );
QgsLayerTreeGroup *childGroup = QgsLayerTree::toGroup( child );
if ( childGroup->customProperty( "embedded" ).toInt() )
{
// make sure to convert the path from relative to absolute
QString projectPath = readPath( childGroup->customProperty( "embedded_project" ).toString() );
childGroup->setCustomProperty( "embedded_project", projectPath );
QgsLayerTreeGroup* newGroup = createEmbeddedGroup( childGroup->name(), projectPath, childGroup->customProperty( "embedded-invisible-layers" ).toStringList() );
QgsLayerTreeGroup *newGroup = createEmbeddedGroup( childGroup->name(), projectPath, childGroup->customProperty( "embedded-invisible-layers" ).toStringList() );
if ( newGroup )
{
QList<QgsLayerTreeNode*> clonedChildren;
foreach ( QgsLayerTreeNode* newGroupChild, newGroup->children() )
foreach ( QgsLayerTreeNode *newGroupChild, newGroup->children() )
clonedChildren << newGroupChild->clone();
delete newGroup;
@ -1005,12 +937,12 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup* group )
}
bool QgsProject::read( QDomNode & layerNode )
bool QgsProject::read( QDomNode &layerNode )
{
QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
return addLayer( layerNode.toElement(), brokenNodes, vectorLayerList );
} // QgsProject::read( QDomNode & layerNode )
} // QgsProject::read( QDomNode &layerNode )
@ -1019,7 +951,7 @@ bool QgsProject::write( QFileInfo const &file )
imp_->file.setFileName( file.filePath() );
return write();
} // QgsProject::write( QFileInfo const & file )
} // QgsProject::write( QFileInfo const &file )
bool QgsProject::write()
@ -1081,7 +1013,7 @@ bool QgsProject::write()
titleNode.appendChild( titleText );
// write layer tree - make sure it is without embedded subgroups
QgsLayerTreeNode* clonedRoot = mRootGroup->clone();
QgsLayerTreeNode *clonedRoot = mRootGroup->clone();
QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ) ); // convert absolute paths to relative paths if required
clonedRoot->writeXML( qgisNode );
@ -1091,7 +1023,7 @@ bool QgsProject::write()
emit writeProject( *doc );
// within top level node save list of layers
const QMap<QString, QgsMapLayer*> & layers = QgsMapLayerRegistry::instance()->mapLayers();
const QMap<QString, QgsMapLayer*> &layers = QgsMapLayerRegistry::instance()->mapLayers();
// Iterate over layers in zOrder
// Call writeXML() on each
@ -1101,8 +1033,7 @@ bool QgsProject::write()
QMap<QString, QgsMapLayer*>::ConstIterator li = layers.constBegin();
while ( li != layers.end() )
{
//QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li);
QgsMapLayer* ml = li.value();
QgsMapLayer *ml = li.value();
if ( ml )
{
@ -1119,9 +1050,10 @@ bool QgsProject::write()
projectLayersNode.appendChild( maplayerElem );
}
else //layer defined in an external project file
else
{
//only save embedded layer if not managed by a legend group
// layer defined in an external project file
// only save embedded layer if not managed by a legend group
if ( emIt.value().second )
{
QDomElement mapLayerElem = doc->createElement( "maplayer" );
@ -1152,22 +1084,14 @@ bool QgsProject::write()
// now wrap it up and ship it to the project file
doc->normalize(); // XXX I'm not entirely sure what this does
//QString xml = doc->toString(4); // write to string with indentation of four characters
// (yes, four is arbitrary)
// const char * xmlString = xml; // debugger probe point
// qDebug( "project file output:\n\n" + xml );
QTextStream projectFileStream( &imp_->file );
//projectFileStream << xml << endl;
doc->save( projectFileStream, 2 ); // save as utf-8
imp_->file.close();
// check if the text stream had no error - if it does
// the user will get a message so they can try to resolve the
// situation e.g. by saving project to a volume with more space
//
if ( projectFileStream.pos() == -1 || imp_->file.error() != QFile::NoError )
{
setError( tr( "Unable to save to file %1. Your project "
@ -1196,7 +1120,7 @@ void QgsProject::clearProperties()
bool
QgsProject::writeEntry( QString const &scope, const QString & key, bool value )
QgsProject::writeEntry( QString const &scope, const QString &key, bool value )
{
dirty( true );
@ -1205,7 +1129,7 @@ QgsProject::writeEntry( QString const &scope, const QString & key, bool value )
bool
QgsProject::writeEntry( QString const &scope, const QString & key,
QgsProject::writeEntry( QString const &scope, const QString &key,
double value )
{
dirty( true );
@ -1215,7 +1139,7 @@ QgsProject::writeEntry( QString const &scope, const QString & key,
bool
QgsProject::writeEntry( QString const &scope, const QString & key, int value )
QgsProject::writeEntry( QString const &scope, const QString &key, int value )
{
dirty( true );
@ -1224,52 +1148,46 @@ QgsProject::writeEntry( QString const &scope, const QString & key, int value )
bool
QgsProject::writeEntry( QString const &scope, const QString & key,
const QString & value )
QgsProject::writeEntry( QString const &scope, const QString &key,
const QString &value )
{
dirty( true );
return addKey_( scope, key, &imp_->properties_, value );
} // QgsProject::writeEntry ( ..., const QString & value )
} // QgsProject::writeEntry ( ..., const QString &value )
bool
QgsProject::writeEntry( QString const &scope, const QString & key,
const QStringList & value )
QgsProject::writeEntry( QString const &scope, const QString &key,
const QStringList &value )
{
dirty( true );
return addKey_( scope, key, &imp_->properties_, value );
} // QgsProject::writeEntry ( ..., const QStringList & value )
} // QgsProject::writeEntry ( ..., const QStringList &value )
QStringList
QgsProject::readListEntry( QString const & scope,
const QString & key,
QgsProject::readListEntry( QString const &scope,
const QString &key,
QStringList def,
bool * ok ) const
bool *ok ) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );
QgsProperty *property = findKey_( scope, key, imp_->properties_ );
QVariant value;
if ( property )
{
value = property->value();
}
bool valid = QVariant::StringList == value.type();
bool valid = QVariant::StringList == value.type();
if ( ok )
*ok = valid;
if ( ok )
{
*ok = valid;
}
if ( valid )
{
return value.toStringList();
if ( valid )
{
return value.toStringList();
}
}
return def;
@ -1277,41 +1195,36 @@ QgsProject::readListEntry( QString const & scope,
QString
QgsProject::readEntry( QString const & scope,
const QString & key,
const QString & def,
bool * ok ) const
QgsProject::readEntry( QString const &scope,
const QString &key,
const QString &def,
bool *ok ) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );
QgsProperty *property = findKey_( scope, key, imp_->properties_ );
QVariant value;
if ( property )
{
value = property->value();
bool valid = value.canConvert( QVariant::String );
if ( ok )
*ok = valid;
if ( valid )
return value.toString();
}
bool valid = value.canConvert( QVariant::String );
if ( ok )
{
*ok = valid;
}
if ( valid )
{
return value.toString();
}
return QString( def );
return def;
} // QgsProject::readEntry
int
QgsProject::readNumEntry( QString const &scope, const QString & key, int def,
bool * ok ) const
QgsProject::readNumEntry( QString const &scope, const QString &key, int def,
bool *ok ) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );
QgsProperty *property = findKey_( scope, key, imp_->properties_ );
QVariant value;
@ -1337,29 +1250,21 @@ QgsProject::readNumEntry( QString const &scope, const QString & key, int def,
double
QgsProject::readDoubleEntry( QString const &scope, const QString & key,
QgsProject::readDoubleEntry( QString const &scope, const QString &key,
double def,
bool * ok ) const
bool *ok ) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );
QVariant value;
QgsProperty *property = findKey_( scope, key, imp_->properties_ );
if ( property )
{
value = property->value();
}
QVariant value = property->value();
bool valid = value.canConvert( QVariant::Double );
bool valid = value.canConvert( QVariant::Double );
if ( ok )
*ok = valid;
if ( ok )
{
*ok = valid;
}
if ( valid )
{
return value.toDouble();
if ( valid )
return value.toDouble();
}
return def;
@ -1367,54 +1272,47 @@ QgsProject::readDoubleEntry( QString const &scope, const QString & key,
bool
QgsProject::readBoolEntry( QString const &scope, const QString & key, bool def,
bool * ok ) const
QgsProject::readBoolEntry( QString const &scope, const QString &key, bool def,
bool *ok ) const
{
QgsProperty * property = findKey_( scope, key, imp_->properties_ );
QVariant value;
QgsProperty *property = findKey_( scope, key, imp_->properties_ );
if ( property )
{
value = property->value();
}
QVariant value = property->value();
bool valid = value.canConvert( QVariant::Bool );
bool valid = value.canConvert( QVariant::Bool );
if ( ok )
*ok = valid;
if ( ok )
{
*ok = valid;
}
if ( valid )
{
return value.toBool();
if ( valid )
return value.toBool();
}
return def;
} // QgsProject::readBoolEntry
bool QgsProject::removeEntry( QString const &scope, const QString & key )
bool QgsProject::removeEntry( QString const &scope, const QString &key )
{
removeKey_( scope, key, imp_->properties_ );
dirty( true );
return ! findKey_( scope, key, imp_->properties_ );
return !findKey_( scope, key, imp_->properties_ );
} // QgsProject::removeEntry
QStringList QgsProject::entryList( QString const &scope, QString const &key ) const
{
QgsProperty * foundProperty = findKey_( scope, key, imp_->properties_ );
QgsProperty *foundProperty = findKey_( scope, key, imp_->properties_ );
QStringList entries;
if ( foundProperty )
{
QgsPropertyKey * propertyKey = dynamic_cast<QgsPropertyKey*>( foundProperty );
QgsPropertyKey *propertyKey = dynamic_cast<QgsPropertyKey*>( foundProperty );
if ( propertyKey )
{ propertyKey->entryList( entries ); }
@ -1426,13 +1324,13 @@ QStringList QgsProject::entryList( QString const &scope, QString const &key ) co
QStringList QgsProject::subkeyList( QString const &scope, QString const &key ) const
{
QgsProperty * foundProperty = findKey_( scope, key, imp_->properties_ );
QgsProperty *foundProperty = findKey_( scope, key, imp_->properties_ );
QStringList entries;
if ( foundProperty )
{
QgsPropertyKey * propertyKey = dynamic_cast<QgsPropertyKey*>( foundProperty );
QgsPropertyKey *propertyKey = dynamic_cast<QgsPropertyKey*>( foundProperty );
if ( propertyKey )
{ propertyKey->subkeyList( entries ); }
@ -1567,7 +1465,7 @@ QString QgsProject::writePath( QString src, QString relativeBasePath ) const
return src;
}
QFileInfo srcFileInfo( src );//QString srcPath = src;
QFileInfo srcFileInfo( src );
QFileInfo projFileInfo( fileName() );
QString srcPath = srcFileInfo.canonicalFilePath();
QString projPath = projFileInfo.canonicalFilePath();
@ -1669,13 +1567,13 @@ void QgsProject::clearError()
setError( QString() );
}
void QgsProject::setBadLayerHandler( QgsProjectBadLayerHandler* handler )
void QgsProject::setBadLayerHandler( QgsProjectBadLayerHandler *handler )
{
delete mBadLayerHandler;
mBadLayerHandler = handler;
}
QString QgsProject::layerIsEmbedded( const QString& id ) const
QString QgsProject::layerIsEmbedded( const QString &id ) const
{
QHash< QString, QPair< QString, bool > >::const_iterator it = mEmbeddedLayers.find( id );
if ( it == mEmbeddedLayers.constEnd() )
@ -1685,8 +1583,8 @@ QString QgsProject::layerIsEmbedded( const QString& id ) const
return it.value().first;
}
bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag )
bool QgsProject::createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
QList< QPair< QgsVectorLayer*, QDomElement > > &vectorLayerList, bool saveFlag )
{
QgsDebugCall;
@ -1711,7 +1609,7 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
prevProjectFilePath = projectFilePath;
}
//does project store pathes absolute or relative?
// does project store pathes absolute or relative?
bool useAbsolutePathes = true;
QDomElement propertiesElem = projectDocument.documentElement().firstChildElement( "properties" );
@ -1733,12 +1631,12 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
QDomNodeList mapLayerNodes = projectLayersElem.elementsByTagName( "maplayer" );
for ( int i = 0; i < mapLayerNodes.size(); ++i )
{
//get layer id
// get layer id
QDomElement mapLayerElem = mapLayerNodes.at( i ).toElement();
QString id = mapLayerElem.firstChildElement( "id" ).text();
if ( id == layerId )
{
//layer can be embedded only once
// layer can be embedded only once
if ( mapLayerElem.attribute( "embedded" ) == "1" )
{
return false;
@ -1746,7 +1644,7 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );
//change datasource path from relative to absolute if necessary
// change datasource path from relative to absolute if necessary
if ( !useAbsolutePathes )
{
QDomElement provider = mapLayerElem.firstChildElement( "provider" );
@ -1793,9 +1691,9 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
}
QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, const QString& projectFilePath, const QStringList &invisibleLayers )
QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers )
{
//open project file, get layer ids in group, add the layers
// open project file, get layer ids in group, add the layers
QFile projectFile( projectFilePath );
if ( !projectFile.open( QIODevice::ReadOnly ) )
{
@ -1808,7 +1706,7 @@ QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, co
return 0;
}
//store identify disabled layers of the embedded project
// store identify disabled layers of the embedded project
QSet<QString> embeddedIdentifyDisabledLayers;
QDomElement disabledLayersElem = projectDocument.documentElement().firstChildElement( "properties" ).firstChildElement( "Identify" ).firstChildElement( "disabledLayers" );
if ( !disabledLayersElem.isNull() )
@ -1820,7 +1718,7 @@ QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, co
}
}
QgsLayerTreeGroup* root = new QgsLayerTreeGroup;
QgsLayerTreeGroup *root = new QgsLayerTreeGroup;
QDomElement layerTreeElem = projectDocument.documentElement().firstChildElement( "layer-tree-group" );
if ( !layerTreeElem.isNull() )
@ -1832,7 +1730,7 @@ QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, co
QgsLayerTreeUtils::readOldLegend( root, projectDocument.documentElement().firstChildElement( "legend" ) );
}
QgsLayerTreeGroup* group = root->findGroup( groupName );
QgsLayerTreeGroup *group = root->findGroup( groupName );
if ( !group || group->customProperty( "embedded" ).toBool() )
{
// embedded groups cannot be embedded again
@ -1841,7 +1739,7 @@ QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, co
}
// clone the group sub-tree (it is used already in a tree, we cannot just tear it off)
QgsLayerTreeGroup* newGroup = QgsLayerTree::toGroup( group->clone() );
QgsLayerTreeGroup *newGroup = QgsLayerTree::toGroup( group->clone() );
delete root;
root = 0;
@ -1873,9 +1771,9 @@ QgsLayerTreeGroup* QgsProject::createEmbeddedGroup( const QString& groupName, co
return newGroup;
}
void QgsProject::initializeEmbeddedSubtree( const QString& projectFilePath, QgsLayerTreeGroup* group )
void QgsProject::initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group )
{
foreach ( QgsLayerTreeNode* child, group->children() )
foreach ( QgsLayerTreeNode *child, group->children() )
{
// all nodes in the subtree will have "embedded" custom property set
child->setCustomProperty( "embedded", 1 );
@ -1894,7 +1792,7 @@ void QgsProject::initializeEmbeddedSubtree( const QString& projectFilePath, QgsL
}
}
void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection )
void QgsProject::setSnapSettingsForLayer( const QString &layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection )
{
QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
@ -1911,10 +1809,10 @@ void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled,
layerIdList.append( layerId );
//enabled
// enabled
enabledList.append( enabled ? "enabled" : "disabled" );
//snap type
// snap type
QString typeString;
if ( type == QgsSnapper::SnapToSegment )
{
@ -1930,13 +1828,13 @@ void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled,
}
snapTypeList.append( typeString );
//units
// units
toleranceUnitList.append( QString::number( unit ) );
//tolerance
// tolerance
toleranceList.append( QString::number( tolerance ) );
//avoid intersection
// avoid intersection
if ( avoidIntersection )
{
avoidIntersectionList.append( layerId );
@ -1951,8 +1849,8 @@ void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled,
emit snapSettingsChanged();
}
bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType& units, double& tolerance,
bool& avoidIntersection ) const
bool QgsProject::snapSettingsForLayer( const QString &layerId, bool &enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType &units, double &tolerance,
bool &avoidIntersection ) const
{
QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
@ -1962,7 +1860,7 @@ bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, Qg
return false;
}
//make sure all lists are long enough
// make sure all lists are long enough
int minListEntries = idx + 1;
if ( layerIdList.size() < minListEntries || enabledList.size() < minListEntries || snapTypeList.size() < minListEntries ||
toleranceUnitList.size() < minListEntries || toleranceList.size() < minListEntries )
@ -1970,10 +1868,10 @@ bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, Qg
return false;
}
//enabled
// enabled
enabled = enabledList.at( idx ) == "enabled";
//snap type
// snap type
QString snapType = snapTypeList.at( idx );
if ( snapType == "to_segment" )
{
@ -1983,12 +1881,12 @@ bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, Qg
{
type = QgsSnapper::SnapToVertexAndSegment;
}
else //to vertex
else // to vertex
{
type = QgsSnapper::SnapToVertex;
}
//units
// units
if ( toleranceUnitList.at( idx ) == "1" )
{
units = QgsTolerance::Pixels;
@ -2002,17 +1900,17 @@ bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, Qg
units = QgsTolerance::LayerUnits;
}
//tolerance
// tolerance
tolerance = toleranceList.at( idx ).toDouble();
//avoid intersection
// avoid intersection
avoidIntersection = ( avoidIntersectionList.indexOf( layerId ) != -1 );
return true;
}
void QgsProject::snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& toleranceUnitList, QStringList& toleranceList,
QStringList& avoidIntersectionList ) const
void QgsProject::snapSettings( QStringList &layerIdList, QStringList &enabledList, QStringList &snapTypeList, QStringList &toleranceUnitList, QStringList &toleranceList,
QStringList &avoidIntersectionList ) const
{
layerIdList = readListEntry( "Digitizing", "/LayerSnappingList" );
enabledList = readListEntry( "Digitizing", "/LayerSnappingEnabledList" );
@ -2047,12 +1945,12 @@ QString QgsProject::homePath() const
return pfi.canonicalPath();
}
QgsRelationManager* QgsProject::relationManager() const
QgsRelationManager *QgsProject::relationManager() const
{
return mRelationManager;
}
QgsLayerTreeGroup* QgsProject::layerTreeRoot() const
QgsLayerTreeGroup *QgsProject::layerTreeRoot() const
{
return mRootGroup;
}