Ejemplo n.º 1
0
/*
 * Initialize the GUI interface for the plugin - this is only called once when the plugin is
 * added to the plugin registry in the QGIS application.
 */
void RoadGraphPlugin::initGui()
{
  // create shorttest path dock
  mQShortestPathDock = new RgShortestPathWidget( mQGisIface->mainWindow(), this );
  mQGisIface->addDockWidget( Qt::LeftDockWidgetArea, mQShortestPathDock );

  // Create the action for tool
  mQSettingsAction  = new QAction( QIcon( ":/roadgraph/road.png" ), tr( "Settings" ), this );
  mQSettingsAction->setObjectName( "mQSettingsAction" );

  // Set the what's this text
  mQSettingsAction->setWhatsThis( tr( "Road graph plugin settings" ) );

  setGuiElementsToDefault();

  // Connect the action to slots
  connect( mQSettingsAction, SIGNAL( triggered() ), this, SLOT( property() ) );

  mQGisIface->addPluginToVectorMenu( tr( "Road graph" ), mQSettingsAction );

  connect( mQGisIface, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
  connect( mQGisIface, SIGNAL( newProjectCreated() ), this, SLOT( newProject() ) );
  connect( mQGisIface, SIGNAL( projectRead() ), mQShortestPathDock, SLOT( clear() ) );
  connect( mQGisIface, SIGNAL( newProjectCreated() ), mQShortestPathDock, SLOT( clear() ) );

  // load settings
  projectRead();
} // RoadGraphPlugin::initGui()
void RoadGraphPlugin::projectRead()
{
  mSettings->read( QgsProject::instance() );
  mTimeUnitName = QgsProject::instance()->readEntry( "roadgraphplugin", "/pluginTimeUnit", "h" );
  mDistanceUnitName = QgsProject::instance()->readEntry( "roadgraphplugin", "/pluginDistanceUnit", "km" );
  mTopologyToleranceFactor =
    QgsProject::instance()->readDoubleEntry( "roadgraphplugin", "/topologyToleranceFactor", 0.0 );
  setGuiElementsToDefault();
}// RoadGraphplguin::projectRead()
/**
 * Slot function for the unload config menu.
 */
void CreateSceFile::unloadConfigSlot()
{
    if(!m_configFileName.isEmpty())
    {
        saveConfigSlot();
    }

    setGuiElementsToDefault();
    m_configFileName = "";
    setTitle(m_configFileName);
    emit configHasToBeSavedSignal();
}
/*
 * Initialize the GUI interface for the plugin - this is only called once when the plugin is
 * added to the plugin registry in the QGIS application.
 */
void RoadGraphPlugin::initGui()
{
  // create shorttest path dock
  mQShortestPathDock = new RgShortestPathWidget( mQGisIface->mainWindow() , this );
  mQGisIface->addDockWidget( Qt::LeftDockWidgetArea, mQShortestPathDock );

  // Create the action for tool
  mQSettingsAction  = new QAction( QIcon( ":/roadgraph/road.png" ), tr( "Road graph settings" ), this );
  mQShowDirectionAction  = new QAction( QIcon( ":/roadgraph/showdirect.png" ), tr( "Show road's direction" ), this );
  mInfoAction = new QAction( QIcon( ":/roadgraph/about.png" ), tr( "About" ), this );

  // Set the what's this text
  mQSettingsAction->setWhatsThis( tr( "Road graph plugin settings" ) );
  mQShowDirectionAction->setWhatsThis( tr( "Roads direction viewer" ) );
  mInfoAction->setWhatsThis( tr( "About Road graph plugin" ) );

  mQShowDirectionAction->setCheckable( true );

  setGuiElementsToDefault();

  // Connect the action to slots
  connect( mQSettingsAction, SIGNAL( triggered() ), this, SLOT( property() ) );
  connect( mQShowDirectionAction, SIGNAL( triggered() ), this, SLOT( onShowDirection() ) );
  connect( mInfoAction, SIGNAL( triggered() ), SLOT( about() ) );

  // Add the icons to the toolbar
  mQGisIface->addToolBarIcon( mQShowDirectionAction );

  mQGisIface->addPluginToMenu( tr( "Road graph" ), mQSettingsAction );
  mQGisIface->addPluginToMenu( tr( "Road graph" ), mQShowDirectionAction );
  mQGisIface->addPluginToMenu( tr( "Road graph" ), mInfoAction );

  connect( mQGisIface->mapCanvas(), SIGNAL( renderComplete( QPainter* ) ), this, SLOT( render( QPainter* ) ) );
  connect( mQGisIface, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
  connect( mQGisIface, SIGNAL( newProjectCreated() ), this, SLOT( newProject() ) );
  connect( mQGisIface, SIGNAL( projectRead() ), mQShortestPathDock, SLOT( clear() ) );
  connect( mQGisIface, SIGNAL( newProjectCreated() ), mQShortestPathDock, SLOT( clear() ) );

  // load settings
  projectRead();
} // RoadGraphPlugin::initGui()
void RoadGraphPlugin::property()
{
  RgSettingsDlg dlg( mSettings, mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );

  dlg.setTimeUnitName( mTimeUnitName );
  dlg.setDistanceUnitName( mDistanceUnitName );
  dlg.setTopologyTolerance( mTopologyToleranceFactor );

  if ( !dlg.exec() )
    return;

  mTimeUnitName = dlg.timeUnitName();
  mDistanceUnitName = dlg.distanceUnitName();
  mTopologyToleranceFactor = dlg.topologyTolerance();

  mSettings->write( QgsProject::instance() );
  QgsProject::instance()->writeEntry( "roadgraphplugin", "/pluginTimeUnit", mTimeUnitName );
  QgsProject::instance()->writeEntry( "roadgraphplugin", "/pluginDistanceUnit", mDistanceUnitName );
  QgsProject::instance()->writeEntry( "roadgraphplugin", "/topologyToleranceFactor", mTopologyToleranceFactor );
  setGuiElementsToDefault();
} //RoadGraphPlugin::property()
void RoadGraphPlugin::newProject()
{
  setGuiElementsToDefault();
}
/**
 * Loads the current config file (m_configFileName).
 */
void CreateSceFile::loadConfigFile(void)
{
    if(!m_configFileName.isEmpty())
    {
        setGuiElementsToDefault();
        setTitle(m_configFileName);

        if(!m_configFileName.isEmpty())
        {
            QFile file(m_configFileName);
            QDomDocument doc("SceConfiguration");

            if (file.open(QFile::ReadOnly))
            {
                file.close();

                if (!doc.setContent(&file))
                {
                    if(!file.readAll().isEmpty())
                    {
                        QMessageBox::critical(this, "parse error", "could not parse " + m_configFileName);

                        m_configFileName = "";
                        setTitle(m_configFileName);
                        emit configHasToBeSavedSignal();
                    }
                }
                else
                {

                    QDomElement docElem = doc.documentElement();
                    ui->filesTableWidget->blockSignals(true);

                    QDomNodeList nodeList = docElem.elementsByTagName("ScriptWindowState");
                    QDomNode nodeItem = nodeList.at(0);
                    ui->withScriptWindowCheckBox->setChecked((nodeItem.attributes().namedItem("withScriptWindow").nodeValue() == "1"));
                    ui->notMinimized->setChecked((nodeItem.attributes().namedItem("notMinimized").nodeValue() == "1"));
                    ui->fileLineEdit->setText(MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("sceFileName").nodeValue()));

                    QStringList versionList = nodeItem.attributes().namedItem("minScVersion").nodeValue().split(".");
                    if(versionList.length() == 2)
                    {
                        ui->minScVersionMajor->setValue(versionList[0].toUInt());
                        ui->minScVersionMinor->setValue(versionList[1].toUInt());
                    }

                    nodeList = docElem.elementsByTagName("File");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString subDirectory = nodeItem.attributes().namedItem("subDirectory").nodeValue();
                        QString type = (nodeItem.attributes().namedItem("type").nodeValue());
                        QString source = MainWindow::convertToAbsolutePath(m_configFileName, nodeItem.attributes().namedItem("source").nodeValue());
                        addTableRow(subDirectory, type, source);
                    }

                    nodeList = docElem.elementsByTagName("ScriptArgument");
                    for (int i = 0; i < nodeList.size(); i++)
                    {
                        nodeItem = nodeList.at(i);
                        QString value = nodeItem.attributes().namedItem("value").nodeValue();
                        ui->argumentsListWidget->addItem(value);
                    }

                    ui->filesTableWidget->blockSignals(false);
                    resizeTableColumnsSlot();

                    QStringList showStrList = m_configFileName.split("/");
                    statusBar()->showMessage(showStrList[showStrList.size() - 1] + " loaded", 5000);
                    setMenuState();
                }
            }
        }
        else
        {
            QMessageBox::critical(this, "could not open file", m_configFileName);

            m_configFileName = "";
            setTitle(m_configFileName);
            emit configHasToBeSavedSignal();
        }
    }
}