Lastly, about the context aware line edit, are you happy with your solution using the new ability to unregister contexts from the context manager?
Doesn't seem to be doing the trick. I still get the warning:
Attempting to register a backend action for a proxy action twice for a single context with name: "InLineEdit" . Last action will be ignored: ""
Looking at deregisterContext, I can see it just removes the context - it doesn't remove any actions associated with that context. Is that by design?
The code I'm using is below - note I am unregistering in the destructor of the ContextAwareLineEdit.
QWidget* ContextAwareItemEditorFactory::createEditor(QVariant::Type type, QWidget* parent) const
{
QWidget* result = nullptr;
if (type == QVariant::String)
{
result = new ContextAwareLineEdit(parent);
}
else
{
result = QItemEditorFactory::createEditor(type, parent);
}
return result;
}
ContextAwareLineEdit::ContextAwareLineEdit(QWidget* parent /*= nullptr*/)
: QLineEdit(parent)
{
inLineEditContext_ = CONTEXT_MANAGER->registerContext(IceContexts::inLineEdit);
QList<int> thisContext;
thisContext.push_front(inLineEditContext_);
// Cut/Copy/Paste to apply in this context
QAction* action = new QAction(this);
connect(action, SIGNAL(triggered()), SLOT(cut()));
ACTION_MANAGER->registerAction(qti_action_EDIT_CUT, action, thisContext);
action = new QAction(this);
connect(action, SIGNAL(triggered()), SLOT(copy()));
ACTION_MANAGER->registerAction(qti_action_EDIT_COPY, action, thisContext);
action = new QAction(this);
connect(action, SIGNAL(triggered()), SLOT(paste()));
ACTION_MANAGER->registerAction(qti_action_EDIT_PASTE, action, thisContext);
}
ContextAwareLineEdit::~ContextAwareLineEdit()
{
CONTEXT_MANAGER->unregisterContext(inLineEditContext_);
}
void ContextAwareLineEdit::focusInEvent(QFocusEvent* e)
{
CONTEXT_MANAGER->setNewContext(inLineEditContext_);
QLineEdit::focusInEvent(e);
}
I can rejig the code so that it registers the context and actions in the c'tor of ContextAwareItemEditorFactory and then hooks them up to ContextAwareLineEdit before it is returned in createEditor()...
As is, when the ContextAwareLineEdit is deleted, it cleans up it's actions and unregisters the context, but you've still got some commands sitting in Qtilities which have had the QActions deleted from underneath them.