[QGIS Commit] r12004 - in trunk/qgis: . src/app src/ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Nov 8 04:51:48 EST 2009
Author: wonder
Date: 2009-11-08 04:51:47 -0500 (Sun, 08 Nov 2009)
New Revision: 12004
Modified:
trunk/qgis/CONTRIBUTORS
trunk/qgis/src/app/qgsconfigureshortcutsdialog.cpp
trunk/qgis/src/app/qgsconfigureshortcutsdialog.h
trunk/qgis/src/app/qgsshortcutsmanager.cpp
trunk/qgis/src/app/qgsshortcutsmanager.h
trunk/qgis/src/ui/qgsconfigureshortcutsdialog.ui
Log:
[FEATURE] Loading and saving of shortcuts.
Contributed by Alexander Bruy - thanks!
Modified: trunk/qgis/CONTRIBUTORS
===================================================================
--- trunk/qgis/CONTRIBUTORS 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/CONTRIBUTORS 2009-11-08 09:51:47 UTC (rev 12004)
@@ -38,3 +38,4 @@
Milena Nowotarska
Anita Graser
Richard Duivenvoorde
+Alexander Bruy
Modified: trunk/qgis/src/app/qgsconfigureshortcutsdialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsconfigureshortcutsdialog.cpp 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/src/app/qgsconfigureshortcutsdialog.cpp 2009-11-08 09:51:47 UTC (rev 12004)
@@ -23,6 +23,11 @@
#include <QKeySequence>
#include <QMessageBox>
+#include <QDomDocument>
+#include <QFileDialog>
+#include <QTextStream>
+#include <QSettings>
+
QgsConfigureShortcutsDialog::QgsConfigureShortcutsDialog( QWidget* parent )
: QDialog( parent ), mGettingShortcut( false )
{
@@ -31,6 +36,8 @@
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* ) ) );
@@ -64,7 +71,132 @@
actionChanged( treeActions->currentItem(), NULL );
}
+void QgsConfigureShortcutsDialog::saveShortcuts()
+{
+ QString fileName = QFileDialog::getSaveFileName( this, tr( "Save shortcuts" ), ".", tr( "XML file (*.xml);; All files (*.*)" ) );
+
+ if ( fileName.isEmpty() )
+ return;
+ QFile file( fileName );
+ if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
+ {
+ QMessageBox::warning( this, tr( "Saving shortcuts" ),
+ tr( "Cannot write file %1:\n%2." )
+ .arg( fileName )
+ .arg( file.errorString() ) );
+ return;
+ }
+
+ QSettings settings;
+
+ QDomDocument doc( "shortcuts" );
+ QDomElement root = doc.createElement( "qgsshortcuts" );
+ root.setAttribute( "version", "1.0" );
+ root.setAttribute( "locale", settings.value( "locale/userLocale", "en_US" ).toString() );
+ doc.appendChild(root);
+
+ settings.beginGroup( "/shortcuts/" );
+ QStringList keys = settings.childKeys();
+
+ QString actionText;
+ QString actionShortcut;
+
+ for( int i = 0; i < keys.count(); ++i )
+ {
+ actionText = keys[ i ];
+ actionShortcut = settings.value( actionText, "" ).toString();
+
+ QDomElement el = doc.createElement( "act" );
+ el.setAttribute( "name", actionText );
+ el.setAttribute( "shortcut", actionShortcut );
+ root.appendChild( el );
+ }
+
+ QTextStream out( &file );
+ doc.save(out, 4);
+}
+
+void QgsConfigureShortcutsDialog::loadShortcuts()
+{
+ QString fileName = QFileDialog::getOpenFileName( this, tr( "Load shortcuts" ), ".", tr( "XML file (*.xml);; 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();
+}
+
void QgsConfigureShortcutsDialog::changeShortcut()
{
setFocus(); // make sure we have focus
@@ -197,7 +329,6 @@
}
}
-
void QgsConfigureShortcutsDialog::updateShortcutText()
{
// update text of the button so that user can see what has typed already
Modified: trunk/qgis/src/app/qgsconfigureshortcutsdialog.h
===================================================================
--- trunk/qgis/src/app/qgsconfigureshortcutsdialog.h 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/src/app/qgsconfigureshortcutsdialog.h 2009-11-08 09:51:47 UTC (rev 12004)
@@ -43,6 +43,8 @@
void changeShortcut();
void resetShortcut();
void setNoShortcut();
+ void saveShortcuts();
+ void loadShortcuts();
void actionChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );
Modified: trunk/qgis/src/app/qgsshortcutsmanager.cpp
===================================================================
--- trunk/qgis/src/app/qgsshortcutsmanager.cpp 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/src/app/qgsshortcutsmanager.cpp 2009-11-08 09:51:47 UTC (rev 12004)
@@ -92,3 +92,14 @@
return NULL;
}
+
+QAction* QgsShortcutsManager::actionByName( QString name )
+{
+ for ( ActionsHash::iterator it = mActions.begin(); it != mActions.end(); ++it )
+ {
+ if ( it.key()->text() == name )
+ return it.key();
+ }
+
+ return NULL;
+}
Modified: trunk/qgis/src/app/qgsshortcutsmanager.h
===================================================================
--- trunk/qgis/src/app/qgsshortcutsmanager.h 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/src/app/qgsshortcutsmanager.h 2009-11-08 09:51:47 UTC (rev 12004)
@@ -49,6 +49,9 @@
//! return action which is associated for the shortcut, NULL if no action is associated
QAction* actionForShortcut( QKeySequence s );
+ // return action by it's name. NULL if nothing found
+ QAction* actionByName( QString name );
+
protected:
QgsShortcutsManager();
Modified: trunk/qgis/src/ui/qgsconfigureshortcutsdialog.ui
===================================================================
--- trunk/qgis/src/ui/qgsconfigureshortcutsdialog.ui 2009-11-08 09:37:09 UTC (rev 12003)
+++ trunk/qgis/src/ui/qgsconfigureshortcutsdialog.ui 2009-11-08 09:51:47 UTC (rev 12004)
@@ -47,6 +47,9 @@
<property name="checkable">
<bool>true</bool>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -54,6 +57,9 @@
<property name="text">
<string>Set none</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -61,27 +67,55 @@
<property name="text">
<string>Set default</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>
</item>
<item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Close</set>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="btnLoadShortcuts">
+ <property name="text">
+ <string>Load...</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnSaveShortcuts">
+ <property name="text">
+ <string>Save...</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</widget>
<tabstops>
<tabstop>treeActions</tabstop>
- <tabstop>btnChangeShortcut</tabstop>
<tabstop>btnSetNoShortcut</tabstop>
<tabstop>btnResetShortcut</tabstop>
+ <tabstop>btnLoadShortcuts</tabstop>
+ <tabstop>btnSaveShortcuts</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
More information about the QGIS-commit
mailing list