コード例 #1
0
void QgsComposerManager::rename_clicked()
{
  QListWidgetItem* item = mComposerListWidget->currentItem();
  if ( !item )
  {
    return;
  }

  QString currentTitle;
  QgsComposer* currentComposer = 0;
  QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find( item );
  if ( it != mItemComposerMap.end() )
  {
    currentComposer = it.value();
    currentTitle = it.value()->title();
  }
  else
  {
    return;
  }
  QString newTitle = QgisApp::instance()->uniqueComposerTitle( this, false, currentTitle );
  if ( newTitle.isNull() )
  {
    return;
  }
  currentComposer->setTitle( newTitle );
  item->setText( newTitle );

  mComposerListWidget->sortItems();
}
コード例 #2
0
void QgsComposerManager::rename_clicked()
{
  QListWidgetItem* item = mComposerListWidget->currentItem();
  if ( !item )
  {
    return;
  }

  QString currentTitle;
  QgsComposer* currentComposer = 0;
  QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find( item );
  if ( it != mItemComposerMap.end() )
  {
    currentComposer = it.value();
    currentTitle = it.value()->title();
  }
  else
  {
    return;
  }
  QString newTitle = QInputDialog::getText( 0, tr( "Change title" ), tr( "Title" ), QLineEdit::Normal, currentTitle );
  if ( newTitle.isNull() )
  {
    return;
  }
  currentComposer->setTitle( newTitle );
  item->setText( newTitle );
}
コード例 #3
0
void QgsComposerManager::on_mAddButton_clicked()
{
  QgsComposer* newComposer = 0;

  newComposer = QgisApp::instance()->createNewComposer();
  if ( !newComposer )
  {
    return;
  }

  if ( mTemplate->currentIndex() > 0 )
  {
    QDomDocument templateDoc;
    QFile templateFile( mTemplate->itemData( mTemplate->currentIndex() ).toString() );
    if ( templateFile.open( QIODevice::ReadOnly ) )
    {
      if ( templateDoc.setContent( &templateFile, false ) )
      {
        newComposer->readXML( templateDoc );
      }
    }
  }

  QListWidgetItem* item = new QListWidgetItem( newComposer->title(), mComposerListWidget );
  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
  mItemComposerMap.insert( item, newComposer );
}
コード例 #4
0
ファイル: qgisappinterface.cpp プロジェクト: exlimit/QGIS
QgsComposerInterface *QgisAppInterface::openComposer( QgsComposition *composition )
{
  QgsComposer *composerObj = qgis->openComposer( composition );
  if ( composerObj )
  {
    return composerObj->iface();
  }
  return nullptr;
}
コード例 #5
0
QgsComposerView* QgisAppInterface::createNewComposer( QString title )
{
  QgsComposer* composerObj = 0;
  composerObj = qgis->createNewComposer( title );
  if ( composerObj )
  {
    return composerObj->view();
  }
  return 0;
}
コード例 #6
0
QgsComposerView* QgisAppInterface::createNewComposer( const QString& title )
{
  QgsComposer* composerObj = nullptr;
  composerObj = qgis->createNewComposer( title );
  if ( composerObj )
  {
    return composerObj->view();
  }
  return nullptr;
}
コード例 #7
0
QgsComposerView* QgisAppInterface::duplicateComposer( QgsComposerView* composerView, QString title )
{
  QgsComposer* composerObj = 0;
  composerObj = qobject_cast<QgsComposer *>( composerView->composerWindow() );
  if ( composerObj )
  {
    QgsComposer* dupComposer = qgis->duplicateComposer( composerObj, title );
    if ( dupComposer )
    {
      return dupComposer->view();
    }
  }
  return 0;
}
コード例 #8
0
void QgsComposerManager::duplicate_clicked()
{
  QListWidgetItem* item = mComposerListWidget->currentItem();
  if ( !item )
  {
    return;
  }

  QgsComposer* currentComposer = 0;
  QString currentTitle;
  QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find( item );
  if ( it != mItemComposerMap.end() )
  {
    currentComposer = it.value();
    currentTitle = it.value()->title();
  }
  else
  {
    return;
  }

  QString newTitle = QgisApp::instance()->uniqueComposerTitle( this, false, currentTitle + tr( " copy" ) );
  if ( newTitle.isNull() )
  {
    return;
  }

  // provide feedback, since loading of template into duplicate composer will be hidden
  QDialog* dlg = currentComposer->busyIndicatorDialog( tr( "Duplicating composer..." ), this );
  dlg->show();

  QgsComposer* newComposer = QgisApp::instance()->duplicateComposer( currentComposer, newTitle );
  dlg->close();

  if ( newComposer )
  {
    // extra activation steps for Windows
    hide();
    newComposer->activate();

    // no need to add new composer to list widget, if just closing this->exec();
    close();
  }
  else
  {
    QMessageBox::warning( this, tr( "Duplicate Composer" ),
                          tr( "Composer duplication failed." ) );
  }
}
コード例 #9
0
void QgsComposerManager::show_clicked()
{
  QListWidgetItem* item = mComposerListWidget->currentItem();
  if ( !item )
  {
    return;
  }

  QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find( item );
  if ( it != mItemComposerMap.end() )
  {
    QgsComposer* c = 0;
    if ( it.value() ) //a normal composer
    {
      c = it.value();
      if ( c )
      {
        // extra activation steps for Windows
        bool shown = c->isVisible();
        hide();

        c->activate();

        // extra activation steps for Windows
        if ( !shown )
        {
          c->on_mActionZoomAll_triggered();
        }
      }
    }
  }
#if 0
  else //create composer from default template
  {
    QMap<QString, QString>::const_iterator templateIt = mDefaultTemplateMap.find( it.key()->text() );
    if ( templateIt == mDefaultTemplateMap.constEnd() )
    {
      return;
    }

    QDomDocument templateDoc;
    QFile templateFile( templateIt.value() );
    if ( !templateFile.open( QIODevice::ReadOnly ) )
    {
      return;
    }

    if ( !templateDoc.setContent( &templateFile, false ) )
    {
      return;
    }
    c = QgisApp::instance()->createNewComposer();
    c->setTitle( it.key()->text() );
    if ( c )
    {
      c->readXML( templateDoc );
      mItemComposerMap.insert( it.key(), c );
    }
  }

  if ( c )
  {
    c->activate();
  }
#endif //0
  close();
}
コード例 #10
0
void QgsComposerManager::on_mAddButton_clicked()
{
  QFile templateFile;
  bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
  if ( loadingTemplate )
  {
    if ( mTemplate->currentIndex() == 1 )
    {
      templateFile.setFileName( mTemplatePathLineEdit->text() );
    }
    else
    {
      templateFile.setFileName( mTemplate->itemData( mTemplate->currentIndex() ).toString() );
    }

    if ( !templateFile.exists() )
    {
      QMessageBox::warning( this, tr( "Template error" ), tr( "Error, template file not found" ) );
      return;
    }
    if ( !templateFile.open( QIODevice::ReadOnly ) )
    {
      QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not read file" ) );
      return;
    }
  }

  QgsComposer* newComposer = 0;
  bool loadedOK = false;

  QString title = QgisApp::instance()->uniqueComposerTitle( this, true );
  if ( title.isNull() )
  {
    return;
  }

  newComposer = QgisApp::instance()->createNewComposer( title );
  if ( !newComposer )
  {
    QMessageBox::warning( this, tr( "Composer error" ), tr( "Error, could not create composer" ) );
    return;
  }
  else
  {
    loadedOK = true;
  }

  if ( loadingTemplate )
  {
    QDomDocument templateDoc;
    if ( templateDoc.setContent( &templateFile, false ) )
    {
      // provide feedback, since composer will be hidden when loading template (much faster)
      // (not needed for empty composer)
      QDialog* dlg = newComposer->busyIndicatorDialog( tr( "Loading template into composer..." ), this );
      dlg->show();
      newComposer->hide();
      loadedOK = newComposer->composition()->loadFromTemplate( templateDoc, 0, false );
      newComposer->activate();
      dlg->close();
    }
  }

  if ( loadedOK )
  {
    // do not close on Add, since user may want to add multiple composers from templates
    QListWidgetItem* item = new QListWidgetItem( newComposer->title(), mComposerListWidget );
    item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
    mItemComposerMap.insert( item, newComposer );

    mComposerListWidget->sortItems();
    mComposerListWidget->setCurrentItem( item );
    mComposerListWidget->setFocus();
  }
  else
  {
    if ( newComposer )
    {
      newComposer->close();
      QgisApp::instance()->deleteComposer( newComposer );
      newComposer = 0;
    }
    QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not load template file" ) );
  }
}
コード例 #11
0
ファイル: qgscomposermanager.cpp プロジェクト: Aladar64/QGIS
void QgsComposerManager::on_mAddButton_clicked()
{
  QFile templateFile;
  bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
  if ( loadingTemplate )
  {
    if ( mTemplate->currentIndex() == 1 )
    {
      templateFile.setFileName( mTemplatePathLineEdit->text() );
    }
    else
    {
      templateFile.setFileName( mTemplate->itemData( mTemplate->currentIndex() ).toString() );
    }

    if ( !templateFile.exists() )
    {
      QMessageBox::warning( this, tr( "Template error" ), tr( "Error, template file not found" ) );
      return;
    }
    if ( !templateFile.open( QIODevice::ReadOnly ) )
    {
      QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not read file" ) );
      return;
    }
  }

  QgsComposer* newComposer = 0;
  bool loadedOK = false;

  QString title = QgisApp::instance()->uniqueComposerTitle( this, true );
  if ( title.isNull() )
  {
    return;
  }

  newComposer = QgisApp::instance()->createNewComposer( title );
  if ( !newComposer )
  {
    QMessageBox::warning( this, tr( "Composer error" ), tr( "Error, could not create composer" ) );
    return;
  }
  else
  {
    loadedOK = true;
  }

  if ( loadingTemplate )
  {
    QDomDocument templateDoc;
    if ( templateDoc.setContent( &templateFile, false ) )
    {
      // provide feedback, since composer will be hidden when loading template (much faster)
      // (not needed for empty composer)
      QDialog* dlg = new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ) );
      dlg->setStyleSheet( QgisApp::instance()->styleSheet() );
      dlg->show();

      newComposer->hide();
      loadedOK = newComposer->composition()->loadFromTemplate( templateDoc, 0, false );
      newComposer->activate();

      dlg->close();
      delete dlg;
      dlg = 0;
    }
  }

  if ( !loadedOK )
  {
    newComposer->close();
    QgisApp::instance()->deleteComposer( newComposer );
    newComposer = 0;
    QMessageBox::warning( this, tr( "Template error" ), tr( "Error, could not load template file" ) );
  }
}