Exemplo n.º 1
0
void QgsAttributeAction::runAction( const QgsAction &action, void ( *executePython )( const QString & ) )
{
  if ( action.type() == QgsAction::OpenUrl )
  {
    QFileInfo finfo( action.action() );
    if ( finfo.exists() && finfo.isFile() )
      QDesktopServices::openUrl( QUrl::fromLocalFile( action.action() ) );
    else
      QDesktopServices::openUrl( QUrl( action.action(), QUrl::TolerantMode ) );
  }
  else if ( action.type() == QgsAction::GenericPython )
  {
    if ( executePython )
    {
      // deprecated
      executePython( action.action() );
    }
    else if ( smPythonExecute )
    {
      // deprecated
      smPythonExecute( action.action() );
    }
    else
    {
      // TODO: capture output from QgsPythonRunner (like QgsRunProcess does)
      QgsPythonRunner::run( action.action() );
    }
  }
  else
  {
    // The QgsRunProcess instance created by this static function
    // deletes itself when no longer needed.
    QgsRunProcess::create( action.action(), action.capture() );
  }
}
Exemplo n.º 2
0
void QgsAttributeActionDialog::init()
{
  // Start from a fresh slate.
  attributeActionTable->setRowCount( 0 );

  // Populate with our actions.
  for ( int i = 0; i < mActions->size(); i++ )
  {
    const QgsAction action = ( *mActions )[i];
    insertRow( i, action.type(), action.name(), action.action(), action.iconPath(), action.capture() );
  }

  updateButtons();
}
Exemplo n.º 3
0
void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action )
{
  QTableWidgetItem* item;
  mAttributeActionTable->insertRow( row );

  // Type
  item = new QTableWidgetItem( textForType( action.type() ) );
  item->setData( Qt::UserRole, action.type() );
  item->setFlags( item->flags() & ~Qt::ItemIsEditable );
  mAttributeActionTable->setItem( row, Type, item );

  // Description
  mAttributeActionTable->setItem( row, Description, new QTableWidgetItem( action.name() ) );

  // Short Title
  mAttributeActionTable->setItem( row, ShortTitle, new QTableWidgetItem( action.shortTitle() ) );

  // Action text
  mAttributeActionTable->setItem( row, ActionText, new QTableWidgetItem( action.action() ) );

  // Capture output
  item = new QTableWidgetItem();
  item->setFlags( item->flags() & ~( Qt::ItemIsEditable ) );
  item->setCheckState( action.capture() ? Qt::Checked : Qt::Unchecked );
  mAttributeActionTable->setItem( row, Capture, item );

  // Capture output
  item = new QTableWidgetItem();
  item->setFlags( item->flags() & ~( Qt::ItemIsEditable ) );
  item->setCheckState( action.showInAttributeTable() ? Qt::Checked : Qt::Unchecked );
  mAttributeActionTable->setItem( row, ShowInAttributeTable, item );

  // Icon
  QIcon icon = action.icon();
  QTableWidgetItem* headerItem = new QTableWidgetItem( icon, "" );
  headerItem->setData( Qt::UserRole, action.iconPath() );
  mAttributeActionTable->setVerticalHeaderItem( row, headerItem );

  updateButtons();
}