Пример #1
0
QT_BEGIN_NAMESPACE

void AdpReader::readData(const QByteArray &contents)
{
    clear();
    m_contents.clear();
    m_keywords.clear();
    m_properties.clear();
    m_files.clear();
    addData(contents);
    while (!atEnd()) {
        readNext();
        if (isStartElement()) {
            if (name().toString().toLower() == QLatin1String("assistantconfig")
                && versionIsAtLeast320(attributes().value(QLatin1String("version")).toString())) {
                readProject();
            } else if (name().toString().toLower() == QLatin1String("dcf")) {
                QString ref = attributes().value(QLatin1String("ref")).toString();
                addFile(ref);
                m_contents.append(ContentItem(attributes().value(QLatin1String("title")).toString(),
                    ref, 0));
                readDCF();
            } else {
                raiseError();
            }
        }
    }
}
Пример #2
0
void ProjectReader::readProject(const QString &fileName) {
    QFile file(fileName);
    if (!openFile(&file)) {
        return;
    }
    
    readProject(&file, QFileInfo(fileName).absolutePath());
}
Пример #3
0
void QHelpProjectDataPrivate::readData(const QByteArray &contents)
{
	addData(contents);
	while (!atEnd()) {
		readNext();
		if (isStartElement()) {
			if (name() == QLatin1String("QtHelpProject") 
                && attributes().value(QLatin1String("version")) == QLatin1String("1.0"))
				readProject();
			else
                raiseError(QObject::tr("Unknown token. Expected \"QtHelpProject\"!"));
		}
	}

    if (hasError()) {
        raiseError(QObject::tr("Error in line %1: %2").arg(lineNumber())
            .arg(errorString()));
    }
}
Пример #4
0
Project * ProjectReader::read(QIODevice * device)
{
  projDir = QDir::currentPath();
  setDevice(device);
  project = 0;

  //message("reading project");

  while (!atEnd()) {
    readNext();
    //message("read: Token (" + tokenString() + "): " + name().toString());
    if (isStartElement()) {
      if (name() == "project")
        readProject();
      else
        raiseError(QObject::tr("This is not an xpro file."));
    }
  }

  if(!error())
    return project;
  else
    return 0;
}
Пример #5
0
/**
   presuming that the caller has already reset the map canvas, map registry, and legend
 */
bool QgsProject::read()
{
  clearError();

  std::auto_ptr< QDomDocument > doc =
    std::auto_ptr < QDomDocument > ( new QDomDocument( "qgis" ) );

  if ( !imp_->file.open( QIODevice::ReadOnly ) )
  {
    imp_->file.close();

    setError( tr( "Unable to open %1" ).arg( imp_->file.fileName() ) );

    return false;
  }

  // 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
#if 0
    QMessageBox::critical( 0, tr( "Project File Read Error" ),
                           tr( "%1 at line %2 column %3" ).arg( errorMsg ).arg( line ).arg( column ) );
#endif

    QString errorString = tr( "Project file read error: %1 at line %2 column %3" )
                          .arg( errorMsg ).arg( line ).arg( column );

    QgsDebugMsg( errorString );

    imp_->file.close();

    setError( tr( "%1 for file %2" ).arg( errorString ).arg( imp_->file.fileName() ) );

    return false;
  }

  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();
  mEmbeddedLayers.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
  QPair< bool, QList<QDomNode> > getMapLayersResults =  _getMapLayers( *doc );

  // review the integrity of the retrieved map layers
  bool clean = getMapLayersResults.first;

  if ( !clean )
  {
    QgsDebugMsg( "Unable to get map layers from project file." );

    if ( ! getMapLayersResults.second.isEmpty() )
    {
      QgsDebugMsg( "there are " + QString::number( getMapLayersResults.second.size() ) + " broken layers" );
    }

    // we let a custom handler to decide what to do with missing layers
    // (default implementation ignores them, there's also a GUI handler that lets user choose correct path)
    mBadLayerHandler->handleBadLayers( getMapLayersResults.second, *doc );
  }

  // read the project: used by map canvas and legend
  emit readProject( *doc );

  // if all went well, we're allegedly in pristine state
  if ( clean )
    dirty( false );

  return true;

} // QgsProject::read
Пример #6
0
Analysis::Analysis(const QString & prjfile):iNodeRoot_(0), semNet_(0)
{                               //file constructor
  init();
  readProject(prjfile);
}
Пример #7
0
/**
   @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
Пример #8
0
void getargs(int ac, char **av)
{
  int i;
  const char *arg;
  char *cptr;
  char buf[1024];

  opt_develop.xGrid = opt_develop.yGrid = 3; // default grid for designer
  opt_develop.murx = 0;              // default option for testing pvdevelop
  opt_develop.ctrlPressed = 0;
  opt_develop.su = 1;                // run pvs as root
  opt_develop.xmax = 1280;           // default dimension for designer
  opt_develop.ymax = 1024;
  strcpy(opt_develop.backupLocation,"..");
  opt_develop.arg_debug = 0;
  opt_develop.arg_action[0] = '\0';
  opt_develop.script = 0;
  opt_develop.arg_mask_to_generate = -1;
  strcpy(opt_develop.arg_project, "pvs");
  strcpy(opt_develop.manual,"/opt/pvb/doc/index.html");
  strcpy(opt_develop.fake_qmake, "");
  for(i=1; i<ac; i++)
  {
    arg = av[i];
    if(strncmp(arg,"-debug",6) == 0)
    {
      opt_develop.arg_debug = 1;
    }
    else if(strncmp(arg,"-action=",8) == 0)
    {
      sscanf(arg,"-action=%s",opt_develop.arg_action);
    }
    else if(strncmp(arg,"-programming_language=",22) == 0)
    {
      sscanf(arg,"-programming_language=%s",buf);
      // add additional language here
      if     (strcmp(buf,"Python") == 0) opt_develop.script = PV_PYTHON;
      else if(strcmp(buf,"Perl")   == 0) opt_develop.script = PV_PERL;
      else if(strcmp(buf,"PHP")    == 0) opt_develop.script = PV_PHP;
      else if(strcmp(buf,"Tcl")    == 0) opt_develop.script = PV_TCL;
      else if(strcmp(buf,"Lua")    == 0) opt_develop.script = PV_LUA;
      else
      {
        printf("programming_language=%s not supported\n", buf);
      }
    }
    else if(strncmp(arg,"-fake",5) == 0)
    {
      strcpy(opt_develop.fake_qmake,"-fake");
    }
    else if(arg[0] != '-')
    {
      if(strlen(arg) < sizeof(opt_develop.arg_project)-1) 
      {
        strcpy(opt_develop.arg_project,arg);
        cptr = strchr(opt_develop.arg_project,'.');
        if(cptr != NULL) *cptr = '\0';
      }
    }
    else if(strncmp(arg,"-",1) == 0)
    {
      usage();
    }
  }
  readProject();
}