// // distance of point q from line through p in direction v // return >0 => q lies left of the line // <0 => q lies right of the line // double QgsGeometryValidator::distLine2Point( const QgsPoint& p, QgsVector v, const QgsPoint& q ) { if ( qgsDoubleNear( v.length(), 0 ) ) { throw QgsException( QObject::tr( "invalid line" ) ); } return ( v.x()*( q.y() - p.y() ) - v.y()*( q.x() - p.x() ) ) / v.length(); }
QgsVector QgsVector::normalized() const { double len = length(); if ( len == 0.0 ) { throw QgsException( QStringLiteral( "normalized vector of null vector undefined" ) ); } return *this / len; }
QgsVector QgsVector::normal() const { double len = length(); if ( len == 0.0 ) { throw QgsException( "normal vector of null vector undefined" ); } return *this / len; }
/** @note it's presumed that the caller has already reset the map canvas, map registry, and legend */ bool QgsProject::read() { std::auto_ptr< QDomDocument > doc = std::auto_ptr < QDomDocument > ( new QDomDocument( "qgis" ) ); if ( !imp_->file.open( QIODevice::ReadOnly ) ) { imp_->file.close(); // even though we got an error, let's make // sure it's closed anyway throw QgsIOException( QObject::tr( "Unable to open " ) + imp_->file.fileName() ); } // location of problem associated with errorMsg int line, column; QString errorMsg; if ( !doc->setContent( &imp_->file, &errorMsg, &line, &column ) ) { // want to make this class as GUI independent as possible; so commented out // QMessageBox::critical( 0x0, "Project File Read Error", // errorMsg + " at line " + QString::number( line ) + // " column " + QString::number( column ) ); QString errorString = QObject::tr( "Project file read error: " ) + errorMsg + QObject::tr( " at line " ) + QString::number( line ) + QObject::tr( " column " ) + QString::number( column ); qDebug( "%s", errorString.toUtf8().constData() ); imp_->file.close(); throw QgsException( errorString + QObject::tr( " for file " ) + imp_->file.fileName() ); } imp_->file.close(); QgsDebugMsg( "Opened document " + imp_->file.fileName() ); QgsDebugMsg( "Project title: " + imp_->title ); // get project version string, if any QgsProjectVersion fileVersion = _getVersion( *doc ); QgsProjectVersion thisVersion( QGis::QGIS_VERSION ); if ( thisVersion > fileVersion ) { QgsLogger::warning( "Loading a file that was saved with an older " "version of qgis (saved in " + fileVersion.text() + ", loaded in " + QGis::QGIS_VERSION + "). Problems may occur." ); QgsProjectFileTransform projectFile( *doc, fileVersion ); //! Shows a warning when an old project file is read. emit oldProjectVersionWarning( fileVersion.text() ); QgsDebugMsg( "Emitting oldProjectVersionWarning(oldVersion)." ); projectFile.dump(); projectFile.updateRevision( thisVersion ); projectFile.dump(); } // before we start loading everything, let's clear out the current set of // properties first so that we don't have the properties from the previous // project still hanging around imp_->clear(); // now get any properties _getProperties( *doc, imp_->properties_ ); QgsDebugMsg( QString::number( imp_->properties_.count() ) + " properties read" ); dump_( imp_->properties_ ); // restore the canvas' area of interest // now get project title _getTitle( *doc, imp_->title ); // get the map layers std::pair< bool, std::list<QDomNode> > getMapLayersResults = _getMapLayers( *doc ); // review the integrity of the retrieved map layers if ( ! getMapLayersResults.first ) { QgsDebugMsg( "Unable to get map layers from project file." ); if ( ! getMapLayersResults.second.empty() ) { QgsDebugMsg( "there are " + QString::number( getMapLayersResults.second.size() ) + " broken layers" ); } // Since we could be executing this from the test harness which // doesn't *have* layers -- nor a GUI for that matter -- we'll just // leave in the whining and boldly stomp on. emit readProject( *doc ); throw QgsProjectBadLayerException( getMapLayersResults.second ); // return false; } // read the project: used by map canvas and legend emit readProject( *doc ); // can't be dirty since we're allegedly in pristine state dirty( false ); return true; } // QgsProject::read