#include <QmitkPreferencesDialog.h>
Classes | |
struct | PrefPage |
Public Member Functions | |
QmitkPreferencesDialog (QWidget *parent=0, Qt::WindowFlags f=0) | |
~QmitkPreferencesDialog () | |
void | SetSelectedPage (const std::string &id) |
Protected Slots | |
void | OnImportButtonClicked (bool triggered=false) |
void | OnExportButtonClicked (bool triggered=false) |
void | OnApplyButtonClicked (bool triggered=false) |
void | OnCloseButtonClicked (bool triggered=false) |
void | OnKeywordTextChanged (const QString &s) |
void | OnKeywordEditingFinished () |
void | OnPreferencesTreeItemSelectionChanged () |
Protected Member Functions | |
bool | eventFilter (QObject *obj, QEvent *event) |
void | UpdateTree () |
Protected Attributes | |
berry::IPreferencesService::WeakPtr | m_PreferencesService |
std::vector< PrefPage > | m_PrefPages |
std::vcl_size_t | m_CurrentPage |
QGridLayout * | m_Layout |
QSplitter * | m_Splitter |
QWidget * | m_LeftPanel |
QGridLayout * | m_LeftLayout |
QLineEdit * | m_Keyword |
QTreeWidget * | m_PreferencesTree |
QWidget * | m_RightPanel |
QGridLayout * | m_RightLayout |
QLabel * | m_Headline |
QStackedWidget * | m_PreferencesPanel |
QPushButton * | m_ImportButton |
QPushButton * | m_ExportButton |
QPushButton * | m_ApplyButton |
QPushButton * | m_CloseButton |
Definition at line 43 of file QmitkPreferencesDialog.h.
QmitkPreferencesDialog::QmitkPreferencesDialog | ( | QWidget * | parent = 0 , |
Qt::WindowFlags | f = 0 |
||
) |
Definition at line 45 of file QmitkPreferencesDialog.cpp.
References berry::Platform::GetExtensionPointService(), berry::Platform::GetServiceRegistry(), ID, m_ApplyButton, m_CloseButton, m_ExportButton, m_Headline, m_ImportButton, m_Keyword, m_Layout, m_LeftLayout, m_LeftPanel, m_PreferencesPanel, m_PreferencesService, m_PreferencesTree, m_PrefPages, m_RightLayout, m_RightPanel, m_Splitter, OnApplyButtonClicked(), OnCloseButtonClicked(), OnExportButtonClicked(), OnImportButtonClicked(), OnKeywordEditingFinished(), OnKeywordTextChanged(), OnPreferencesTreeItemSelectionChanged(), and UpdateTree().
: QDialog(parent, f), m_CurrentPage(0) { // m_PreferencesService m_PreferencesService = berry::Platform::GetServiceRegistry().GetServiceById<berry::IPreferencesService>(berry::IPreferencesService::ID); // m_PrefPages berry::IExtensionPointService::Pointer extensionPointService = berry::Platform::GetExtensionPointService(); berry::IConfigurationElement::vector prefPages(extensionPointService->GetConfigurationElementsFor("org.blueberry.ui.preferencePages")); berry::IConfigurationElement::vector keywordExts(extensionPointService->GetConfigurationElementsFor("org.blueberry.ui.keywords")); berry::IConfigurationElement::vector::iterator prefPagesIt; std::string id; std::string name; std::string category; std::string className; std::vector<std::string> keywords; vector<berry::IConfigurationElement::Pointer> keywordRefs; berry::IConfigurationElement::vector::iterator keywordRefsIt; berry::IConfigurationElement::vector::iterator keywordExtsIt; string keywordRefId; string keywordId; string keywordLabels; for (prefPagesIt = prefPages.begin(); prefPagesIt != prefPages.end(); ++prefPagesIt) { keywords.clear(); id.clear(); name.clear(); className.clear(); category.clear(); keywordRefId.clear(); keywordId.clear(); keywordLabels.clear(); if((*prefPagesIt)->GetAttribute("id", id) && (*prefPagesIt)->GetAttribute("name", name) && (*prefPagesIt)->GetAttribute("class", className)) { (*prefPagesIt)->GetAttribute("category", category); //# collect keywords keywordRefs = (*prefPagesIt)->GetChildren("keywordreference"); // get all keyword references for (keywordRefsIt = keywordRefs.begin() ; keywordRefsIt != keywordRefs.end(); ++keywordRefsIt) // iterate over all refs { (*keywordRefsIt)->GetAttribute("id", keywordRefId); // get referenced id for (keywordExtsIt = keywordExts.begin(); keywordExtsIt != keywordExts.end(); ++keywordExtsIt) // iterate over all keywords { (*keywordExtsIt)->GetAttribute("id", keywordId); // get keyword id if(keywordId == keywordRefId) // if referenced id is equals the current keyword id { //# collect all keywords from label attribute with a tokenizer (*keywordExtsIt)->GetAttribute("label", keywordLabels); break; // break here; possibly search for other referenced keywords } } } // add information as PrefPage m_PrefPages.push_back(PrefPage(id, name, category, className, keywordLabels, berry::IConfigurationElement::Pointer(*prefPagesIt))); } } //#QWidget //# m_Keyword m_Keyword = new QLineEdit(""); //m_Keyword->installEventFilter(this); QObject::connect(m_Keyword, SIGNAL(editingFinished()), this, SLOT(OnKeywordEditingFinished())); QObject::connect(m_Keyword, SIGNAL(textChanged ( const QString & )), this, SLOT(OnKeywordTextChanged(const QString &))); //# m_PreferencesTree m_PreferencesTree = new QTreeWidget; m_PreferencesTree->setHeaderHidden(true); QObject::connect(m_PreferencesTree, SIGNAL(itemSelectionChanged()), this, SLOT(OnPreferencesTreeItemSelectionChanged())); //# m_LeftLayout m_LeftLayout = new QGridLayout; m_LeftLayout->setContentsMargins(0,0,0,0); m_LeftLayout->setSpacing(0); m_LeftLayout->addWidget(m_Keyword, 0, 0); m_LeftLayout->addWidget(m_PreferencesTree, 1, 0); //# m_LeftPanel m_LeftPanel = new QWidget; m_LeftPanel->setLayout(m_LeftLayout); //# m_Headline m_Headline = new QLabel(""); m_Headline->setStyleSheet("background-color: silver; " "border-style: solid; border-width: 1px;" "border-color: white; font: bold 13px; color: white;"); //# m_PreferencesPanel m_PreferencesPanel = new QStackedWidget; //# m_RightLayout m_RightLayout = new QGridLayout; m_RightLayout->setRowStretch(0, 1); m_RightLayout->setRowStretch(1, 20); m_RightLayout->setContentsMargins(0,0,0,0); m_RightLayout->setSpacing(0); m_RightLayout->addWidget(m_Headline, 0, 0); m_RightLayout->addWidget(m_PreferencesPanel, 1, 0); //# m_RightPanel m_RightPanel = new QWidget; m_RightPanel->setLayout(m_RightLayout); //# m_Splitter m_Splitter = new QSplitter(Qt::Horizontal); m_Splitter->setContentsMargins(0,0,0,0); //m_Splitter->setFrameStyle(QFrame::Plain | QFrame::Sunken); m_Splitter->setLineWidth(2); m_Splitter->addWidget(m_LeftPanel); m_Splitter->addWidget(m_RightPanel); //QList<int> sizes; sizes.push_back(this->width()*(1/3)); sizes.push_back(this->width()*(2/3)); //m_Splitter->setSizes(sizes); m_Splitter->setStretchFactor(0,0); m_Splitter->setStretchFactor(1,2); //# m_ImportButton m_ImportButton = new QPushButton(QString(tr("Import ..."))); QObject::connect(m_ImportButton, SIGNAL(clicked(bool)), this, SLOT(OnImportButtonClicked(bool))); m_ImportButton->setIcon(QIcon(":/org.mitk.gui.qt.common/edit-redo.png")); m_ImportButton->setFlat(true); m_ImportButton->setDefault(false); //# m_ExportButton m_ExportButton = new QPushButton(QString(tr("Export ...")), this); QObject::connect(m_ExportButton, SIGNAL(clicked(bool)), this, SLOT(OnExportButtonClicked(bool))); m_ExportButton->setIcon(QIcon(":/org.mitk.gui.qt.common/edit-undo.png")); m_ExportButton->setFlat(true); m_ExportButton->setDefault(false); //# m_ApplyButton m_ApplyButton = new QPushButton(QString(tr("OK")), this); QObject::connect(m_ApplyButton, SIGNAL(clicked(bool)), this, SLOT(OnApplyButtonClicked(bool))); m_ApplyButton->setIcon(QIcon(":/org.mitk.gui.qt.common/document-save.png")); m_ApplyButton->setFlat(true); m_ApplyButton->setDefault(false); //# m_CloseButton m_CloseButton = new QPushButton(QString(tr("Close")), this); QObject::connect(m_CloseButton, SIGNAL(clicked(bool)), this, SLOT(OnCloseButtonClicked(bool))); m_CloseButton->setIcon(QIcon(":/org.mitk.gui.qt.common/system-log-out.png")); m_CloseButton->setFlat(true); m_CloseButton->setDefault(true); m_CloseButton->setFocus(); //# m_Layout m_Layout = new QGridLayout; //m_Layout->setContentsMargins(0,0,0,0); //m_Layout->setSpacing(2); //m_Layout->setRowStretch(0, 20); //m_Layout->setRowStretch(1, 1); m_Layout->addWidget(m_Splitter, 0, 0, 1, 4); m_Layout->addWidget(m_ImportButton, 2, 0); m_Layout->addWidget(m_ExportButton, 2, 1); m_Layout->addWidget(m_ApplyButton, 2, 2); m_Layout->addWidget(m_CloseButton, 2, 3); // this this->setModal(true); this->setSizeGripEnabled(true); this->setWhatsThis("Dialog to set application wide preferences"); this->setWindowIcon(QIcon(":/org.mitk.gui.qt.common/preferences-system.png")); QRect parentGeometry = parent->geometry(); int w = parentGeometry.width()/2; int h = parentGeometry.height()/2; int x = parentGeometry.x()+(parentGeometry.width()-w)/2; int y = parentGeometry.y()+(parentGeometry.height()-h)/2; this->setGeometry(x,y,w,h); this->setWindowTitle("Preferences"); this->setLayout(m_Layout); this->UpdateTree(); }
QmitkPreferencesDialog::~QmitkPreferencesDialog | ( | ) |
Definition at line 225 of file QmitkPreferencesDialog.cpp.
{ }
bool QmitkPreferencesDialog::eventFilter | ( | QObject * | obj, |
QEvent * | event | ||
) | [protected] |
Definition at line 376 of file QmitkPreferencesDialog.cpp.
References m_Keyword.
{ if(obj == m_Keyword) { if(event->type() == QEvent::FocusIn && m_Keyword->text() == "search ...") { m_Keyword->setText(""); m_Keyword->setStyleSheet("color: black;"); } else if(event->type() == QEvent::FocusOut && m_Keyword->text() == "") { m_Keyword->setText("search ..."); m_Keyword->setStyleSheet("color: gray;"); } } return true; }
void QmitkPreferencesDialog::OnApplyButtonClicked | ( | bool | triggered = false ) |
[protected, slot] |
Every preference page has its own preferences, which should stay the same after a system restart.
Therefore this method flushes all the preferences, every time a change in the preferences is
performed and confirmed.
Definition at line 329 of file QmitkPreferencesDialog.cpp.
References berry::WeakPointer< TObjectType >::Lock(), m_CurrentPage, m_PreferencesService, m_PrefPages, and berry::IPreferencePage::PerformOk().
Referenced by QmitkPreferencesDialog().
{ berry::IQtPreferencePage* prefPage = 0; for(vector<PrefPage>::iterator it = m_PrefPages.begin(); it != m_PrefPages.end(); ++it, ++m_CurrentPage) { prefPage = it->prefPage; if(prefPage) prefPage->PerformOk(); } berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); if (prefService) { prefService->GetSystemPreferences()->Flush(); } this->done(QDialog::Accepted); }
void QmitkPreferencesDialog::OnCloseButtonClicked | ( | bool | triggered = false ) |
[protected, slot] |
Definition at line 356 of file QmitkPreferencesDialog.cpp.
References m_CurrentPage, m_PrefPages, and berry::IPreferencePage::PerformCancel().
Referenced by QmitkPreferencesDialog().
{ berry::IQtPreferencePage* prefPage = m_PrefPages[m_CurrentPage].prefPage; if(prefPage) prefPage->PerformCancel(); this->done(QDialog::Accepted); }
void QmitkPreferencesDialog::OnExportButtonClicked | ( | bool | triggered = false ) |
[protected, slot] |
Definition at line 290 of file QmitkPreferencesDialog.cpp.
References berry::SmartPointer< TObjectType >::Cast(), berry::SmartPointer< TObjectType >::IsNotNull(), berry::WeakPointer< TObjectType >::Lock(), m_PreferencesService, MITK_ERROR, and MITK_INFO.
Referenced by QmitkPreferencesDialog().
{ try { berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); if(prefService.IsNotNull()) { berry::IBerryPreferencesService::Pointer berryPrefService = prefService.Cast<berry::IBerryPreferencesService>(); if(berryPrefService != 0) { QFileDialog fd(this, "Choose file to import preferences", "", "XML files (*.xml)" ); fd.setFileMode(QFileDialog::AnyFile); QStringList fileNames; if (fd.exec()) { fileNames = fd.selectedFiles(); if(fileNames.size()>0) { Poco::File f(fileNames.at(0).toStdString()); berryPrefService->ExportPreferences(f, ""); MITK_INFO("QmitkPreferencesDialog") << "Preferences successfully exported to " << f.path(); } } } } } catch (Poco::Exception& pe) { QMessageBox::critical(this, "Error Exporting", pe.message().c_str()); MITK_ERROR("QmitkPreferencesDialog") << pe.what(); } catch (std::exception& e) { QMessageBox::critical(this, "Error Exporting", e.what()); MITK_ERROR("QmitkPreferencesDialog") << e.what(); } }
void QmitkPreferencesDialog::OnImportButtonClicked | ( | bool | triggered = false ) |
[protected, slot] |
Definition at line 242 of file QmitkPreferencesDialog.cpp.
References berry::SmartPointer< TObjectType >::Cast(), berry::SmartPointer< TObjectType >::IsNotNull(), berry::WeakPointer< TObjectType >::Lock(), m_CurrentPage, m_PreferencesService, m_PrefPages, MITK_ERROR, MITK_INFO, and berry::IPreferencePage::Update().
Referenced by QmitkPreferencesDialog().
{ int answer = QMessageBox::question(this, "Importing Preferences" , "All existing preferences will be overwritten!\nAre you sure that you want to import other preferences?", QMessageBox::Yes | QMessageBox::No ); if(answer == QMessageBox::No) return; try { berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); if(prefService.IsNotNull()) { berry::IBerryPreferencesService::Pointer berryPrefService = prefService.Cast<berry::IBerryPreferencesService>(); if(berryPrefService != 0) { QFileDialog fd(this, "Choose file to import preferences", "", "XML files (*.xml)" ); fd.setFileMode(QFileDialog::ExistingFile); QStringList fileNames; if (fd.exec()) { fileNames = fd.selectedFiles(); if(fileNames.size()>0) { Poco::File f(fileNames.at(0).toStdString()); berryPrefService->ImportPreferences(f, ""); berry::IQtPreferencePage* prefPage = m_PrefPages[m_CurrentPage].prefPage; if(prefPage) prefPage->Update(); MITK_INFO("QmitkPreferencesDialog") << "Preferences successfully imported from " << f.path(); } } } } } catch (Poco::Exception& pe) { QMessageBox::critical(this, "Error Importing", pe.message().c_str()); MITK_ERROR("QmitkPreferencesDialog") << pe.what(); } catch (std::exception& e) { QMessageBox::critical(this, "Error Importing", e.what()); MITK_ERROR("QmitkPreferencesDialog") << e.what(); } }
void QmitkPreferencesDialog::OnKeywordEditingFinished | ( | ) | [protected, slot] |
Definition at line 372 of file QmitkPreferencesDialog.cpp.
Referenced by QmitkPreferencesDialog().
{ }
void QmitkPreferencesDialog::OnKeywordTextChanged | ( | const QString & | s ) | [protected, slot] |
Definition at line 365 of file QmitkPreferencesDialog.cpp.
References UpdateTree().
Referenced by QmitkPreferencesDialog().
{ // search for text this->UpdateTree(); }
void QmitkPreferencesDialog::OnPreferencesTreeItemSelectionChanged | ( | ) | [protected, slot] |
Definition at line 394 of file QmitkPreferencesDialog.cpp.
References berry::IQtPreferencePage::CreateQtControl(), m_CurrentPage, m_Headline, m_PreferencesPanel, m_PreferencesTree, and m_PrefPages.
Referenced by QmitkPreferencesDialog().
{ if(m_PreferencesTree == 0) return; // TODO: create page and show it QList<QTreeWidgetItem *> selectedItems = m_PreferencesTree->selectedItems(); if(selectedItems.size()>0) { m_CurrentPage = 0; for(vector<PrefPage>::iterator it = m_PrefPages.begin(); it != m_PrefPages.end(); ++it, ++m_CurrentPage) { if(it->treeWidgetItem == selectedItems.at(0)) { m_Headline->setText(QString::fromStdString(it->name)); if(it->prefPage == 0) { it->prefPage = dynamic_cast<berry::IQtPreferencePage*>(it->confElem->CreateExecutableExtension<berry::IPreferencePage>("class")); it->prefPage->CreateQtControl(m_PreferencesPanel); m_PreferencesPanel->addWidget(it->prefPage->GetQtControl()); } m_PreferencesPanel->setCurrentWidget(it->prefPage->GetQtControl()); break; } } } }
void QmitkPreferencesDialog::SetSelectedPage | ( | const std::string & | id ) |
Definition at line 229 of file QmitkPreferencesDialog.cpp.
References m_PreferencesTree, and m_PrefPages.
{ for(vector<PrefPage>::iterator it = m_PrefPages.begin(); it != m_PrefPages.end(); ++it) { if(it->id == id) { m_PreferencesTree->setCurrentItem(it->treeWidgetItem); break; } } }
void QmitkPreferencesDialog::UpdateTree | ( | ) | [protected] |
Definition at line 425 of file QmitkPreferencesDialog.cpp.
References m_Keyword, m_PreferencesTree, and m_PrefPages.
Referenced by OnKeywordTextChanged(), and QmitkPreferencesDialog().
{ if(m_PreferencesTree == 0) return; //m_PreferencesTree->clear(); string keyword = m_Keyword->text().toStdString(); map<std::string, QTreeWidgetItem*> items; for(vector<PrefPage>::iterator it = m_PrefPages.begin(); it != m_PrefPages.end(); ++it) { if(it->treeWidgetItem == 0) { if(it->category.empty()) { it->treeWidgetItem = new QTreeWidgetItem(m_PreferencesTree); } else { it->treeWidgetItem = new QTreeWidgetItem(items[it->category]); } it->treeWidgetItem->setText(0, QString::fromStdString(it->name)); items[it->id] = it->treeWidgetItem; } // hide treeWidgetItem if keyword not matches if(!keyword.empty()) { if( it->keywords.find(keyword) == string::npos ) it->treeWidgetItem->setHidden(true); else { //#make the whole branch visible QTreeWidgetItem* treeWidgetParent = it->treeWidgetItem->parent(); while(treeWidgetParent!=0) { treeWidgetParent->setHidden(false); treeWidgetParent->setExpanded(true); treeWidgetParent = treeWidgetParent->parent(); } it->treeWidgetItem->setHidden(false); QFont f = it->treeWidgetItem->font(0); f.setBold(true); it->treeWidgetItem->setFont(0, f); } } else { QFont f = it->treeWidgetItem->font(0); f.setBold(false); it->treeWidgetItem->setFont(0, f); it->treeWidgetItem->setHidden(false); } } if(m_PrefPages.size()>0) { if(m_PrefPages.front().treeWidgetItem != 0) m_PrefPages.front().treeWidgetItem->setSelected(true); } }
QPushButton* QmitkPreferencesDialog::m_ApplyButton [protected] |
Definition at line 112 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QPushButton* QmitkPreferencesDialog::m_CloseButton [protected] |
Definition at line 113 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
std::vcl_size_t QmitkPreferencesDialog::m_CurrentPage [protected] |
Definition at line 94 of file QmitkPreferencesDialog.h.
Referenced by OnApplyButtonClicked(), OnCloseButtonClicked(), OnImportButtonClicked(), and OnPreferencesTreeItemSelectionChanged().
QPushButton* QmitkPreferencesDialog::m_ExportButton [protected] |
Definition at line 111 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QLabel* QmitkPreferencesDialog::m_Headline [protected] |
Definition at line 107 of file QmitkPreferencesDialog.h.
Referenced by OnPreferencesTreeItemSelectionChanged(), and QmitkPreferencesDialog().
QPushButton* QmitkPreferencesDialog::m_ImportButton [protected] |
Definition at line 110 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QLineEdit* QmitkPreferencesDialog::m_Keyword [protected] |
Definition at line 102 of file QmitkPreferencesDialog.h.
Referenced by eventFilter(), QmitkPreferencesDialog(), and UpdateTree().
QGridLayout* QmitkPreferencesDialog::m_Layout [protected] |
Definition at line 97 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QGridLayout* QmitkPreferencesDialog::m_LeftLayout [protected] |
Definition at line 101 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QWidget* QmitkPreferencesDialog::m_LeftPanel [protected] |
Definition at line 100 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QStackedWidget* QmitkPreferencesDialog::m_PreferencesPanel [protected] |
Definition at line 108 of file QmitkPreferencesDialog.h.
Referenced by OnPreferencesTreeItemSelectionChanged(), and QmitkPreferencesDialog().
The Preferences Service to retrieve and store preferences.
Definition at line 88 of file QmitkPreferencesDialog.h.
Referenced by OnApplyButtonClicked(), OnExportButtonClicked(), OnImportButtonClicked(), and QmitkPreferencesDialog().
QTreeWidget* QmitkPreferencesDialog::m_PreferencesTree [protected] |
Definition at line 103 of file QmitkPreferencesDialog.h.
Referenced by OnPreferencesTreeItemSelectionChanged(), QmitkPreferencesDialog(), SetSelectedPage(), and UpdateTree().
std::vector<PrefPage> QmitkPreferencesDialog::m_PrefPages [protected] |
Saves all treewidgetitems in a map, the key is the id of the preferencepage.
Definition at line 93 of file QmitkPreferencesDialog.h.
Referenced by OnApplyButtonClicked(), OnCloseButtonClicked(), OnImportButtonClicked(), OnPreferencesTreeItemSelectionChanged(), QmitkPreferencesDialog(), SetSelectedPage(), and UpdateTree().
QGridLayout* QmitkPreferencesDialog::m_RightLayout [protected] |
Definition at line 106 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QWidget* QmitkPreferencesDialog::m_RightPanel [protected] |
Definition at line 105 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().
QSplitter* QmitkPreferencesDialog::m_Splitter [protected] |
Definition at line 98 of file QmitkPreferencesDialog.h.
Referenced by QmitkPreferencesDialog().