oopapidocs  2.0
actiontableeditor.cpp
00001 #include <QTableView>
00002 #include <QMenu>
00003 #include <QHeaderView>
00004 #include <QSortFilterProxyModel>
00005 #include <QApplication>
00006 #include <QSettings>
00007 #include "ui_actiontableeditor.h"
00008 #include "actiontablemodel.h"
00009 #include "actiontableeditor.h"
00010 #include "actioneditordialog.h"
00011 
00012 //start id="setup"
00013 ActionTableEditor::ActionTableEditor(QWidget* parent)
00014     :  QDialog(parent), m_ui(new Ui::ActionTableEditor) {
00015     // Designer UI class initialization
00016     m_ui->setupUi(this);
00017     m_model = new ActionTableModel(allActions(), this);
00018     setupSortFilter();
00019 }
00020 
00021 ActionTableEditor::
00022 ActionTableEditor(QList<QAction*> actions, QWidget* parent) :
00023   QDialog(parent) {
00024     m_ui->setupUi(this);
00025     m_model = new ActionTableModel(actions, this);
00026     setupSortFilter();
00027 }
00028 
00029 QList<QAction*> ActionTableEditor::allActions() {
00030     QList<QAction*> actions;
00031 
00032     foreach (QAction* a, qApp->findChildren<QAction*>()) {
00033         if (a->children().size() > 0) continue;
00034         if (a->text().size() > 0) actions << a;
00035     }
00036     foreach (QWidget* w, qApp->topLevelWidgets())
00037         foreach (QAction* a, w->findChildren<QAction*>()) {
00038             // skip menus
00039             if (qobject_cast<QMenu*>(a->parent()) != 0) continue;
00040             if (a->text().size() > 0) actions << a;
00041         }
00042     return actions;
00043 }
00044 //start id=dialog
00045 void ActionTableEditor::
00046 on_m_tableView_activated(const QModelIndex& idx) {
00047     int row = idx.row();
00048     QAction* action = m_model->action(row);
00049     ActionEditorDialog aed(action);
00050 
00051     int result = aed.exec();
00052     if (result ==  QDialog::Accepted) {
00053         QKeySequence ks = aed.keySequence();
00054         m_model->setData(idx, ks.toString());
00055         m_changedActions << action;
00056     }
00057 }
00058 //end
00059 //start id=settings
00060 void ActionTableEditor::accept() {
00061     QSettings s;
00062     s.beginGroup("shortcut");
00063     foreach (QAction* act, m_changedActions) {
00064         s.setValue(act->text(), act->shortcut() );
00065     }
00066     s.endGroup();
00067     QDialog::accept();
00068 }
00069 //end
00070 void ActionTableEditor::restoreShortcuts(QList<QAction*> actions) {
00071     QSettings s;
00072     s.beginGroup("shortcut");
00073     foreach (QAction* act, actions) {
00074         QVariant v = s.value(act->text(), QVariant());
00075         if (!v.isNull()) {
00076             QKeySequence ks = v.value<QKeySequence>();
00077             act->setShortcut(ks);
00078         }
00079     }
00080     s.endGroup();
00081 }
00082 //start id="sortfilter"
00083 void ActionTableEditor::setupSortFilter() {
00084     m_sortFilterProxy = new QSortFilterProxyModel(this);
00085     m_sortFilterProxy->setSourceModel(m_model);       /* SortFilterProxy source model set to ActionTableModel. */
00086     m_ui->m_tableView->setModel(m_sortFilterProxy);   /* Table view model set to proxy model instead of ActionTableModel. */    
00087     m_sortFilterProxy->setFilterKeyColumn(-1);        /* Filter on all fields. */
00088 
00089 }
00090 void ActionTableEditor::on_m_filterField_textChanged  /* Auto-connected slot. */  
00091     (const QString& newText) { 
00092     m_sortFilterProxy->setFilterFixedString(newText); /* Change the filter string. */
00093 }
00094 //end
00095 ActionTableEditor::~ActionTableEditor() {
00096     delete m_ui; /* the other pointer members are QObject with this as parent */
00097 }
00098 
00099 void ActionTableEditor::changeEvent(QEvent* e) {
00100     QWidget::changeEvent(e);
00101     switch (e->type()) {
00102     case QEvent::LanguageChange:
00103         m_ui->retranslateUi(this);
00104         break;
00105     default:
00106         break;
00107     }
00108 }
00109 
00110 
 All Classes Namespaces Functions Enumerations