Fixed crash with separator - #158.

This commit is contained in:
Martin Rotter 2016-03-17 20:04:17 +01:00
parent a889db4f6b
commit ae9a6e7d61
2 changed files with 33 additions and 17 deletions

View File

@ -69,9 +69,11 @@ void PlainToolButton::setChecked(bool checked) {
void PlainToolButton::reactOnActionChange(QAction *action) { void PlainToolButton::reactOnActionChange(QAction *action) {
QAction *real_action = action == NULL ? qobject_cast<QAction*>(sender()) : action; QAction *real_action = action == NULL ? qobject_cast<QAction*>(sender()) : action;
if (real_action != NULL) {
setEnabled(real_action->isEnabled()); setEnabled(real_action->isEnabled());
setCheckable(real_action->isCheckable()); setCheckable(real_action->isCheckable());
setChecked(real_action->isChecked()); setChecked(real_action->isChecked());
setIcon(real_action->icon()); setIcon(real_action->icon());
setToolTip(real_action->toolTip()); setToolTip(real_action->toolTip());
} }
}

View File

@ -151,20 +151,29 @@ void StatusBar::loadChangeableActions(const QStringList &action_names) {
widget_to_add->setVisible(false); widget_to_add->setVisible(false);
} }
else {
if (action_name == SEPARATOR_ACTION_NAME) {
QLabel *lbl = new QLabel(QSL(""));
widget_to_add = lbl;
action_to_add = new QAction(this);
action_to_add->setProperty("should_remove_action", true);
}
else { else {
// Add originally toolbar action. // Add originally toolbar action.
PlainToolButton *tool_button = new PlainToolButton(this); PlainToolButton *tool_button = new PlainToolButton(this);
tool_button->reactOnActionChange(matching_action); tool_button->reactOnActionChange(matching_action);
action_to_add = matching_action;
widget_to_add = tool_button; widget_to_add = tool_button;
action_to_add = matching_action;
matching_action->setProperty("should_remove", true);
connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger())); connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger()));
connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange())); connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange()));
} }
action_to_add->setProperty("should_remove_widget", true);
}
action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add)); action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add));
addPermanentWidget(widget_to_add); addPermanentWidget(widget_to_add);
addAction(action_to_add); addAction(action_to_add);
@ -185,18 +194,23 @@ void StatusBar::clear() {
while (!actions().isEmpty()) { while (!actions().isEmpty()) {
QAction *act = actions().at(0); QAction *act = actions().at(0);
QWidget *widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : NULL; QWidget *widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : NULL;
bool should_remove = act->property("remove_widget").isValid(); bool should_remove_widget = act->property("should_remove_widget").isValid();
bool should_remove_action = act->property("should_remove_action").isValid();
removeAction(act);
if (widget != NULL) { if (widget != NULL) {
removeWidget(widget); removeWidget(widget);
widget->setVisible(false); widget->setVisible(false);
if (should_remove) { if (should_remove_widget) {
widget->deleteLater(); widget->deleteLater();
} }
}
removeAction(act); if (should_remove_action) {
act->deleteLater();
}
}
} }
} }