示例#1
0
bool QgsGrassTools::loadConfig( QString filePath, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct )
{
  QgsDebugMsg( filePath );
  modulesTreeWidget->clear();
  modulesTreeWidget->setIconSize( QSize( 80, 22 ) );

  QFile file( filePath );

  if ( !file.exists() )
  {
    QMessageBox::warning( 0, tr( "Warning" ), tr( "The config file (%1) not found." ).arg( filePath ) );
    return false;
  }
  if ( ! file.open( QIODevice::ReadOnly ) )
  {
    QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open config file (%1)." ).arg( filePath ) );
    return false;
  }

  QDomDocument doc( "qgisgrass" );
  QString err;
  int line, column;
  if ( !doc.setContent( &file,  &err, &line, &column ) )
  {
    QString errmsg = tr( "Cannot read config file (%1):" ).arg( filePath )
                     + tr( "\n%1\nat line %2 column %3" ).arg( err ).arg( line ).arg( column );
    QgsDebugMsg( errmsg );
    QMessageBox::warning( 0, tr( "Warning" ), errmsg );
    file.close();
    return false;
  }

  QDomElement docElem = doc.documentElement();
  QDomNodeList modulesNodes = docElem.elementsByTagName( "modules" );

  if ( modulesNodes.count() == 0 )
  {
    file.close();
    return false;
  }

  QDomNode modulesNode = modulesNodes.item( 0 );
  QDomElement modulesElem = modulesNode.toElement();

  // Go through the sections and modules and add them to the list view
  addModules( 0, modulesElem, modulesTreeWidget, modulesListModel, direct );
  if ( direct )
  {
    removeEmptyItems( modulesTreeWidget );
  }
  modulesTreeWidget->topLevelItem( 0 )->setExpanded( true );

  file.close();
  return true;
}
bool QgsGrassTools::loadConfig( QString filePath )
{
  QgsDebugMsg( filePath );
  mModulesTree->clear();
  mModulesTree->setIconSize( QSize( 80, 22 ) );

  QFile file( filePath );

  if ( !file.exists() )
  {
    QMessageBox::warning( 0, tr( "Warning" ), tr( "The config file (" ) + filePath + tr( ") not found." ) );
    return false;
  }
  if ( ! file.open( QIODevice::ReadOnly ) )
  {
    QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open config file (" ) + filePath + tr( ")" ) );
    return false;
  }

  QDomDocument doc( "qgisgrass" );
  QString err;
  int line, column;
  if ( !doc.setContent( &file,  &err, &line, &column ) )
  {
    QString errmsg = tr( "Cannot read config file (" ) + filePath + "):\n" + err + tr( "\nat line " )
                     + QString::number( line ) + tr( " column " ) + QString::number( column );
    QgsDebugMsg( errmsg );
    QMessageBox::warning( 0, tr( "Warning" ), errmsg );
    file.close();
    return false;
  }

  QDomElement docElem = doc.documentElement();
  QDomNodeList modulesNodes = docElem.elementsByTagName( "modules" );

  if ( modulesNodes.count() == 0 )
  {
    file.close();
    return false;
  }

  QDomNode modulesNode = modulesNodes.item( 0 );
  QDomElement modulesElem = modulesNode.toElement();

  // Go through the sections and modules and add them to the list view
  addModules( 0, modulesElem );

  mModulesTree->topLevelItem( 0 )->setExpanded( true );

  file.close();
  return true;
}
示例#3
0
文件: nproj.cpp 项目: orpiske/nus
int NProj::run(void) {
	if (NFile::exists("CMakeLists.txt") && !m_force) {
		throw NException("There's already a CMakeLists.txt file in this"
			" project. Remove it before running nproj", 
			NException::TOOLS);
	}

	m_output.setFileName("CMakeLists.txt");
	m_output.open(NIODevice::Truncate);	

	setupHeader();
	addModules();
	addExecutable();
	addLibrary();

	m_output.closeDevice();
	
	return 0;
}
示例#4
0
void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct )
{
  QDomNode n = element.firstChild();

  QTreeWidgetItem *item;
  QTreeWidgetItem *lastItem = 0;
  while ( !n.isNull() )
  {
    QDomElement e = n.toElement();
    if ( !e.isNull() )
    {
// QgsDebugMsg(QString("tag = %1").arg(e.tagName()));

      if ( e.tagName() != "section" && e.tagName() != "grass" )
      {
        QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) );
        continue;
      }

      // Check GRASS version
      QString version_min = e.attribute( "version_min" );
      QString version_max = e.attribute( "version_max" );

      if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) )
      {
        n = n.nextSibling();
        continue;
      }

      if ( parent )
      {
        item = new QTreeWidgetItem( parent, lastItem );
      }
      else
      {
        item = new QTreeWidgetItem( modulesTreeWidget, lastItem );
      }

      if ( e.tagName() == "section" )
      {
        QString label = QApplication::translate( "grasslabel", e.attribute( "label" ).toUtf8() );
        QgsDebugMsg( QString( "label = %1" ).arg( label ) );
        item->setText( 0, label );
        item->setExpanded( false );

        addModules( item, e, modulesTreeWidget, modulesListModel, direct );

        lastItem = item;
      }
      else if ( e.tagName() == "grass" )
      { // GRASS module
        QString name = e.attribute( "name" );
        QgsDebugMsg( QString( "name = %1" ).arg( name ) );

        QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
        QgsGrassModule::Description description = QgsGrassModule::description( path );

        if ( !direct || description.direct )
        {
          QString label = description.label;
          QPixmap pixmap = QgsGrassModule::pixmap( path, 32 );

          item->setText( 0, name + " - " + label );
          item->setIcon( 0, QIcon( pixmap ) );
          item->setText( 1, name );
          lastItem = item;

          // Add this item to our list model
          QStandardItem * mypDetailItem = new QStandardItem( name + "\n" + label );
          mypDetailItem->setData( name, Qt::UserRole + 1 ); //for calling runModule later
          QString mySearchText = name + " - " + label;
          mypDetailItem->setData( mySearchText, Qt::UserRole + 2 ); //for filtering later
          mypDetailItem->setData( pixmap, Qt::DecorationRole );
          mypDetailItem->setCheckable( false );
          mypDetailItem->setEditable( false );
          // setData in the delegate with a variantised QgsDetailedItemData
          QgsDetailedItemData myData;
          myData.setTitle( name );
          myData.setDetail( label );
          myData.setIcon( pixmap );
          myData.setCheckable( false );
          myData.setRenderAsWidget( false );
          QVariant myVariant = qVariantFromValue( myData );
          mypDetailItem->setData( myVariant, Qt::UserRole );
          modulesListModel->appendRow( mypDetailItem );
        }
        else
        {
          delete item;
        }
      }
    }
    n = n.nextSibling();
  }

}
示例#5
0
void GuestToolsListener::setupConnection()
{
    qDebug() << "setting up guest tools";
    addModules();
    connect(toolSocket, SIGNAL(readyRead()), this, SLOT(receiveData()));
}
void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element )
{
  QDomNode n = element.firstChild();

  QTreeWidgetItem *item;
  QTreeWidgetItem *lastItem = 0;
  while ( !n.isNull() )
  {
    QDomElement e = n.toElement();
    if ( !e.isNull() )
    {
// QgsDebugMsg(QString("tag = %1").arg(e.tagName()));

      if ( e.tagName() == "section" && e.tagName() == "grass" )
      {
        QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) );
        continue;
      }

      if ( parent )
      {
        item = new QTreeWidgetItem( parent, lastItem );
      }
      else
      {
        item = new QTreeWidgetItem( mModulesTree, lastItem );
      }

      if ( e.tagName() == "section" )
      {
        QString label = e.attribute( "label" );
        QgsDebugMsg( QString( "label = %1" ).arg( label ) );
        item->setText( 0, label );
        item->setExpanded( false );

        addModules( item, e );

        lastItem = item;
      }
      else if ( e.tagName() == "grass" )
      { // GRASS module
        QString name = e.attribute( "name" );
        QgsDebugMsg( QString( "name = %1" ).arg( name ) );

        QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
        QString label = QgsGrassModule::label( path );
        QPixmap pixmap = QgsGrassModule::pixmap( path, 25 );

        item->setText( 0, name + " - " + label );
        item->setIcon( 0, QIcon( pixmap ) );
        item->setText( 1, name );
        lastItem = item;


        //
        // Experimental work by Tim - add this item to our list model
        //
        QStandardItem * mypDetailItem = new QStandardItem( name );
        mypDetailItem->setData( name, Qt::UserRole + 1 ); //for calling runModule later
        QString mySearchText = name + " - " + label;
        mypDetailItem->setData( mySearchText, Qt::UserRole + 2 ); //for filtering later
        mypDetailItem->setData( pixmap, Qt::DecorationRole );
        mypDetailItem->setCheckable( false );
        mypDetailItem->setEditable( false );
        // setData in the delegate with a variantised QgsDetailedItemData
        QgsDetailedItemData myData;
        myData.setTitle( name );
        myData.setDetail( label );
        myData.setIcon( pixmap );
        myData.setCheckable( false );
        myData.setRenderAsWidget( true );
        QVariant myVariant = qVariantFromValue( myData );
        mypDetailItem->setData( myVariant, Qt::UserRole );
        mModelTools->appendRow( mypDetailItem );
        //
        // End of experimental work by Tim
        //
      }
    }
    n = n.nextSibling();
  }
}
示例#7
0
void BtBookshelfModel::addModules(const QList<CSwordModuleInfo *> & modules) {
    addModules(modules.toSet());
}