WIP: some refinement

This commit is contained in:
Matthias Koefferlein 2020-08-08 21:32:21 +02:00
parent cdce2cb151
commit 4254221e6e
6 changed files with 47 additions and 9 deletions

View File

@ -92,8 +92,8 @@ struct EOPCompareOp
} }
}; };
EditorOptionsPages::EditorOptionsPages (QWidget *parent, const std::vector<edt::EditorOptionsPage *> &pages, lay::Dispatcher *root) EditorOptionsPages::EditorOptionsPages (QWidget *parent, const std::vector<edt::EditorOptionsPage *> &pages, lay::Dispatcher *dispatcher)
: QFrame (parent), mp_root (root) : QFrame (parent), mp_dispatcher (dispatcher)
{ {
QVBoxLayout *ly1 = new QVBoxLayout (this); QVBoxLayout *ly1 = new QVBoxLayout (this);
ly1->setMargin (0); ly1->setMargin (0);
@ -148,7 +148,7 @@ EditorOptionsPages::activate_page (edt::EditorOptionsPage *page)
{ {
try { try {
if (page->active ()) { if (page->active ()) {
page->setup (mp_root); page->setup (mp_dispatcher);
} }
} catch (...) { } catch (...) {
// catch any errors related to configuration file errors etc. // catch any errors related to configuration file errors etc.
@ -192,7 +192,7 @@ EditorOptionsPages::setup ()
for (std::vector <edt::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) { for (std::vector <edt::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
if ((*p)->active ()) { if ((*p)->active ()) {
(*p)->setup (mp_root); (*p)->setup (mp_dispatcher);
} }
} }
@ -210,7 +210,8 @@ EditorOptionsPages::do_apply ()
{ {
for (std::vector <edt::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) { for (std::vector <edt::EditorOptionsPage *>::iterator p = m_pages.begin (); p != m_pages.end (); ++p) {
if ((*p)->active ()) { if ((*p)->active ()) {
(*p)->apply (mp_root); // NOTE: we apply to the root dispatcher, so other dispatchers (views) get informed too.
(*p)->apply (mp_dispatcher->dispatcher ());
} }
} }
} }

View File

@ -111,7 +111,7 @@ public slots:
private: private:
std::vector <edt::EditorOptionsPage *> m_pages; std::vector <edt::EditorOptionsPage *> m_pages;
lay::Dispatcher *mp_root; lay::Dispatcher *mp_dispatcher;
QTabWidget *mp_pages; QTabWidget *mp_pages;
void update (edt::EditorOptionsPage *page); void update (edt::EditorOptionsPage *page);

View File

@ -2362,6 +2362,12 @@ private:
db::cell_index_type m_topcell; db::cell_index_type m_topcell;
}; };
void
MainService::config_finalize ()
{
setup_pages (view ());
}
void void
MainService::paste () MainService::paste ()
{ {

View File

@ -199,6 +199,12 @@ public:
*/ */
virtual void paste (); virtual void paste ();
/**
* @brief Implementation of "config_finalize"
* This implementation will update the editor option page's parameters.
*/
virtual void config_finalize ();
private: private:
// The layout view that this service is attached to // The layout view that this service is attached to
lay::LayoutView *mp_view; lay::LayoutView *mp_view;

View File

@ -377,12 +377,12 @@ show_editor_options_page (lay::LayoutView *view)
} }
} }
edt::EditorOptionsPages *pages = new edt::EditorOptionsPages (view->editor_options_frame (), prop_dialog_pages, view->dispatcher ()); edt::EditorOptionsPages *pages = new edt::EditorOptionsPages (view->editor_options_frame (), prop_dialog_pages, view);
view->editor_options_frame ()->layout ()->addWidget (pages); view->editor_options_frame ()->layout ()->addWidget (pages);
} }
void static
activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool active) edt::EditorOptionsPages *get_pages_widget (lay::LayoutView *view)
{ {
// TODO: is there a better way to find the editor options pages? // TODO: is there a better way to find the editor options pages?
edt::EditorOptionsPages *eo_pages = 0; edt::EditorOptionsPages *eo_pages = 0;
@ -391,6 +391,13 @@ activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool
eo_pages = dynamic_cast<edt::EditorOptionsPages *> (*c); eo_pages = dynamic_cast<edt::EditorOptionsPages *> (*c);
} }
return eo_pages;
}
void
activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool active)
{
edt::EditorOptionsPages *eo_pages = get_pages_widget (view);
if (!eo_pages) { if (!eo_pages) {
return; return;
} }
@ -400,6 +407,19 @@ activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool
} }
} }
void
setup_pages (lay::LayoutView *view)
{
edt::EditorOptionsPages *eo_pages = get_pages_widget (view);
if (!eo_pages) {
return;
}
for (std::vector<edt::EditorOptionsPage *>::const_iterator op = eo_pages->pages ().begin (); op != eo_pages->pages ().end (); ++op) {
(*op)->setup (view);
}
}
class PartialPluginDeclaration class PartialPluginDeclaration
: public lay::PluginDeclaration : public lay::PluginDeclaration
{ {

View File

@ -60,6 +60,11 @@ namespace edt
* This will show or hide the editor properties pages for the respective service. * This will show or hide the editor properties pages for the respective service.
*/ */
void activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool active); void activate_service (lay::LayoutView *view, const lay::PluginDeclaration *pd, bool active);
/**
* @brief Setup the editor option pages for the given view
*/
void setup_pages (lay::LayoutView *view);
} }
#endif #endif