tictactoetaskmenu.cpp Example File
taskmenuextension/tictactoetaskmenu.cpp
#include "tictactoe.h"
#include "tictactoedialog.h"
#include "tictactoetaskmenu.h"
#include <QtDesigner/QDesignerFormEditorInterface>
#include <QAction>
TicTacToeTaskMenu::TicTacToeTaskMenu(TicTacToe *tic, QObject *parent)
: QObject(parent)
, editStateAction(new QAction(tr("Edit State..."), this))
, ticTacToe(tic)
{
connect(editStateAction, &QAction::triggered, this, &TicTacToeTaskMenu::editState);
}
void TicTacToeTaskMenu::editState()
{
TicTacToeDialog dialog(ticTacToe);
dialog.exec();
}
QAction *TicTacToeTaskMenu::preferredEditAction() const
{
return editStateAction;
}
QList<QAction *> TicTacToeTaskMenu::taskActions() const
{
return QList<QAction *>{editStateAction};
}
TicTacToeTaskMenuFactory::TicTacToeTaskMenuFactory(QExtensionManager *parent)
: QExtensionFactory(parent)
{
}
QObject *TicTacToeTaskMenuFactory::createExtension(QObject *object,
const QString &iid,
QObject *parent) const
{
if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
return nullptr;
if (TicTacToe *tic = qobject_cast<TicTacToe*>(object))
return new TicTacToeTaskMenu(tic, parent);
return nullptr;
}