QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget* parent, QgsShortcutsManager* manager )
    : QDialog( parent )
    , mManager( manager )
    , mGettingShortcut( false )
    , mModifiers( 0 )
    , mKey( 0 )
{
  setupUi( this );

  if ( !mManager )
    mManager = QgsShortcutsManager::instance();

  connect( btnChangeShortcut, SIGNAL( clicked() ), this, SLOT( changeShortcut() ) );
  connect( btnResetShortcut, SIGNAL( clicked() ), this, SLOT( resetShortcut() ) );
  connect( btnSetNoShortcut, SIGNAL( clicked() ), this, SLOT( setNoShortcut() ) );
  connect( btnSaveShortcuts, SIGNAL( clicked() ), this, SLOT( saveShortcuts() ) );
  connect( btnLoadShortcuts, SIGNAL( clicked() ), this, SLOT( loadShortcuts() ) );

  connect( treeActions, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
           this, SLOT( actionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );

  populateActions();

  restoreState();
}
QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget* parent )
    : QDialog( parent ), mGettingShortcut( false )
{
  setupUi( this );

  connect( btnChangeShortcut, SIGNAL( clicked() ), this, SLOT( changeShortcut() ) );
  connect( btnResetShortcut, SIGNAL( clicked() ), this, SLOT( resetShortcut() ) );
  connect( btnSetNoShortcut, SIGNAL( clicked() ), this, SLOT( setNoShortcut() ) );
  connect( btnSaveShortcuts, SIGNAL( clicked() ), this, SLOT( saveShortcuts() ) );
  connect( btnLoadShortcuts, SIGNAL( clicked() ), this, SLOT( loadShortcuts() ) );

  connect( treeActions, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
           this, SLOT( actionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );

  populateActions();
}
Esempio n. 3
0
QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget *parent, QgsShortcutsManager *manager )
  : QDialog( parent )
  , mManager( manager )
{
  setupUi( this );
  QgsGui::enableAutoGeometryRestore( this );
  connect( mLeFilter, &QgsFilterLineEdit::textChanged, this, &QgsConfigureShortcutsDialog::mLeFilter_textChanged );

  if ( !mManager )
    mManager = QgsGui::shortcutsManager();

  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsConfigureShortcutsDialog::showHelp ); // Vérifier nommage des boutons
  connect( btnChangeShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::changeShortcut );
  connect( btnResetShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::resetShortcut );
  connect( btnSetNoShortcut, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::setNoShortcut );
  connect( btnSaveShortcuts, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::saveShortcuts );
  connect( btnLoadShortcuts, &QAbstractButton::clicked, this, &QgsConfigureShortcutsDialog::loadShortcuts );

  connect( treeActions, &QTreeWidget::currentItemChanged,
           this, &QgsConfigureShortcutsDialog::actionChanged );

  populateActions();
}
void QgsConfigureShortcutsDialog::loadShortcuts()
{
  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load shortcuts" ), ".", tr( "XML file" ) + " (*.xml);;" + tr( "All files" ) + " (*)" );

  if ( fileName.isEmpty() )
  {
    return;
  }

  QFile file( fileName );
  if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
  {
    QMessageBox::warning( this, tr( "Loading shortcuts" ),
                          tr( "Cannot read file %1:\n%2." )
                          .arg( fileName )
                          .arg( file.errorString() ) );
    return;
  }

  QDomDocument  doc;
  QString errorStr;
  int errorLine;
  int errorColumn;

  if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
  {
    QMessageBox::information( this, tr( "Loading shortcuts" ),
                              tr( "Parse error at line %1, column %2:\n%3" )
                              .arg( errorLine )
                              .arg( errorColumn )
                              .arg( errorStr ) );
    return;
  }

  QDomElement root = doc.documentElement();
  if ( root.tagName() != "qgsshortcuts" )
  {
    QMessageBox::information( this, tr( "Loading shortcuts" ),
                              tr( "The file is not an shortcuts exchange file." ) );
    return;
  }

  QSettings settings;
  QString currentLocale;

  bool localeOverrideFlag = settings.value( "locale/overrideFlag", false ).toBool();
  if ( localeOverrideFlag )
  {
    currentLocale = settings.value( "locale/userLocale", "en_US" ).toString();
  }
  else // use QGIS locale
  {
    currentLocale = QLocale::system().name();
  }

  if ( root.attribute( "locale" ) != currentLocale )
  {
    QMessageBox::information( this, tr( "Loading shortcuts" ),
                              tr( "The file contains shortcuts created with different locale, so you can't use it." ) );
    return;
  }

  QAction* action;
  QString actionName;
  QString actionShortcut;

  QDomElement child = root.firstChildElement();
  while ( !child.isNull() )
  {
    actionName = child.attribute( "name" );
    actionShortcut = child.attribute( "shortcut" );
    action = QgsShortcutsManager::instance()->actionByName( actionName );
    QgsShortcutsManager::instance()->setActionShortcut( action, actionShortcut );
    child = child.nextSiblingElement();
  }

  treeActions->clear();
  populateActions();
}