WIP: batch mode does not crash anymore (QAction cannot be created in non-GUI mode)

This commit is contained in:
Matthias Koefferlein 2021-12-05 17:07:40 +01:00
parent 1777002d4a
commit e07b9dc609
4 changed files with 53 additions and 22 deletions

View File

@ -159,7 +159,7 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
: QMainWindow (0),
tl::Object (),
lay::DispatcherDelegate (),
m_dispatcher (this),
m_dispatcher (this, this),
m_text_progress (this, 10 /*verbosity threshold*/),
m_mode (std::numeric_limits<unsigned int>::max ()),
mp_setup_form (0),
@ -179,9 +179,6 @@ MainWindow::MainWindow (QApplication *app, const char *name, bool undo_enabled)
mp_app (app),
m_manager (undo_enabled)
{
// install us as menu widget parent
m_dispatcher.set_menu_parent_widget (this);
// ensures the deferred method scheduler is present
tl::DeferredMethodScheduler::instance ();

View File

@ -36,7 +36,6 @@ static Dispatcher *ms_dispatcher_instance = 0;
Dispatcher::Dispatcher (Plugin *parent, bool standalone)
: Plugin (parent, standalone),
m_menu (this),
mp_menu_parent_widget (0),
mp_delegate (0)
{
@ -45,13 +44,38 @@ Dispatcher::Dispatcher (Plugin *parent, bool standalone)
}
}
Dispatcher::Dispatcher (QWidget *menu_parent_widget, Plugin *parent, bool standalone)
: Plugin (parent, standalone),
mp_menu_parent_widget (menu_parent_widget),
mp_delegate (0)
{
if (mp_menu_parent_widget) {
mp_menu.reset (new lay::AbstractMenu (this));
}
if (! parent && ! ms_dispatcher_instance) {
ms_dispatcher_instance = this;
}
}
Dispatcher::Dispatcher (DispatcherDelegate *delegate, Plugin *parent, bool standalone)
: Plugin (parent, standalone),
m_menu (this),
mp_menu_parent_widget (0),
mp_delegate (delegate)
{
if (! ms_dispatcher_instance) {
if (! parent && ! ms_dispatcher_instance) {
ms_dispatcher_instance = this;
}
}
Dispatcher::Dispatcher (QWidget *menu_parent_widget, DispatcherDelegate *delegate, Plugin *parent, bool standalone)
: Plugin (parent, standalone),
mp_menu_parent_widget (menu_parent_widget),
mp_delegate (delegate)
{
if (mp_menu_parent_widget) {
mp_menu.reset (new lay::AbstractMenu (this));
}
if (! parent && ! ms_dispatcher_instance) {
ms_dispatcher_instance = this;
}
}
@ -66,9 +90,11 @@ Dispatcher::~Dispatcher ()
bool
Dispatcher::configure (const std::string &name, const std::string &value)
{
std::vector<lay::ConfigureAction *> ca = m_menu.configure_actions (name);
for (std::vector<lay::ConfigureAction *>::const_iterator a = ca.begin (); a != ca.end (); ++a) {
(*a)->configure (value);
if (mp_menu) {
std::vector<lay::ConfigureAction *> ca = mp_menu->configure_actions (name);
for (std::vector<lay::ConfigureAction *>::const_iterator a = ca.begin (); a != ca.end (); ++a) {
(*a)->configure (value);
}
}
if (mp_delegate) {

View File

@ -117,6 +117,15 @@ public:
*/
Dispatcher (Plugin *parent = 0, bool standalone = false);
/**
* @brief The constructor
*
* @param menu_parent_widget If not 0, indicates that this is a GUI mode dispatcher providing an abstract menu
* @param parent Usually 0, but a dispatcher may have parents. In this case, the dispatcher is not the actual dispatcher, but the real plugin chain's root is.
* @param standalone The standalone flag passed to the plugin constructor.
*/
Dispatcher (QWidget *menu_parent_widget, Plugin *parent = 0, bool standalone = false);
/**
* @brief The root constructor
*
@ -124,6 +133,14 @@ public:
*/
Dispatcher (DispatcherDelegate *delegate, Plugin *parent = 0, bool standalone = false);
/**
* @brief The root constructor
*
* @param menu_parent_widget If not 0, indicates that this is a GUI mode dispatcher providing an abstract menu
* @param delegate The notification receiver for dispatcher events
*/
Dispatcher (QWidget *menu_parent_widget, DispatcherDelegate *delegate, Plugin *parent = 0, bool standalone = false);
/**
* @brief Destructor
*/
@ -207,14 +224,6 @@ public:
return mp_menu_parent_widget;
}
/**
* @brief Gets the parent widget
*/
void set_menu_parent_widget (QWidget *w)
{
mp_menu_parent_widget = w;
}
/**
* @brief Returns true, if the dispatcher supplies a user interface
*/
@ -227,7 +236,7 @@ public:
*/
AbstractMenu *menu ()
{
return (dispatcher () == this) ? &m_menu : dispatcher ()->menu ();
return (dispatcher () == this) ? mp_menu.get () : dispatcher ()->menu ();
}
protected:
@ -239,7 +248,7 @@ private:
Dispatcher (const Dispatcher &);
Dispatcher &operator= (const Dispatcher &);
lay::AbstractMenu m_menu;
std::unique_ptr<lay::AbstractMenu> mp_menu;
QWidget *mp_menu_parent_widget;
DispatcherDelegate *mp_delegate;
};

View File

@ -252,7 +252,7 @@ static LayoutView *ms_current = 0;
LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin_parent, QWidget *parent, const char *name, unsigned int options)
: QFrame (parent),
lay::Dispatcher (plugin_parent, false /*not standalone*/),
lay::Dispatcher (this, plugin_parent, false /*not standalone*/),
m_editable (editable),
m_options (options),
m_annotation_shapes (manager),
@ -261,7 +261,6 @@ LayoutView::LayoutView (db::Manager *manager, bool editable, lay::Plugin *plugin
{
// either it's us or the parent has a dispatcher
tl_assert (dispatcher () != 0);
set_menu_parent_widget (this);
// ensures the deferred method scheduler is present
tl::DeferredMethodScheduler::instance ();