16#include <config-kdsme.h>
19#include "ui_mainwindow.h"
28#include "parsehelper.h"
33#include <QCoreApplication>
38#include <QStandardItemModel>
39#include <QStandardPaths>
46enum PresetsModelDataRoles : quint16
48 AbsoluteFilePathRole = Qt::UserRole + 1
54 : QMainWindow(parent, f)
56 , m_presetsModel(new QStandardItemModel(this))
58 , m_stateMachineView(nullptr)
63 setupStateMachineView();
64 setupObjectInspector();
69 setWindowTitle(tr(
"State Machine Editor"));
84 m_presetsModel->clear();
86 const QDir dir(presetsDir);
88 qWarning() <<
"Non-existent presets location:" << presetsDir;
91 const QStringList files = dir.entryList(QDir::Files);
92 for (
const QString &file : files) {
93 if (!file.endsWith(u
".scxml"))
96 auto *item =
new QStandardItem(file);
97 item->setData(dir.absoluteFilePath(file), AbsoluteFilePathRole);
98 m_presetsModel->appendRow(item);
101 m_presetsModel->setHeaderData(0, Qt::Horizontal, tr(
"Preset"));
104void MainWindow::setupStateMachineView()
108 setCentralWidget(m_stateMachineView);
111void MainWindow::setupPresetsView()
113 ui->presetsTreeView->setModel(m_presetsModel);
114 ui->presetsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
115 connect(ui->presetsTreeView, &QTreeView::clicked,
this, &MainWindow::handlePresetActivated);
118void MainWindow::setupObjectInspector()
122 ui->transitionsView->setModel(m_transitionsModel);
127void MainWindow::setupActions()
129 auto action =
new QAction(tr(
"New"),
this);
131 ui->mainToolBar->addAction(action);
141 m_owningStateMachine.reset(stateMachine);
148 m_transitionsModel->
setState(stateMachine);
151 Q_ASSERT(selectionModel);
152 ui->statesView->setSelectionModel(selectionModel);
153 ui->propertyEditorWidget->setSelectionModel(selectionModel);
154 ui->propertyEditorWidget->setCommandController(m_stateMachineView->
commandController());
156 ui->statesView->expandAll();
169 ui->presetsTreeView->setCurrentIndex(QModelIndex());
174 const QModelIndex selected = ui->presetsTreeView->currentIndex();
175 return selected.data(AbsoluteFilePathRole).toString();
178void MainWindow::importFromScxmlFile(
const QString &filePath)
180 if (!filePath.isEmpty()) {
185 m_owningStateMachine.reset(stateMachine);
192 const QModelIndex match = m_presetsModel->match(m_presetsModel->index(0, 0), AbsoluteFilePathRole, QFileInfo(filePath).absoluteFilePath(), 1, Qt::MatchExactly).value(0);
193 ui->presetsTreeView->setCurrentIndex(match);
196void MainWindow::handlePresetActivated(
const QModelIndex &index)
198 const QString filePath = index.data(AbsoluteFilePathRole).toString();
199 if (filePath.isEmpty())
202 importFromScxmlFile(filePath);
QItemSelectionModel * selectionModel() const
void setEditModeEnabled(bool editModeEnabled)
void setLabel(const QString &label)
StateModel * stateModel() const
void setRootState(State *rootState)
Widget for displaying a KDSME::StateMachine in a Qt Quick based view.
KDSME::StateMachineScene * scene
KDSME::CommandController * commandController
KDSME::EditController * editController
void setState(State *state)
QString selectedFile() const
When in PresetsInputMode, return the currently selected file name.
void setStateMachine(KDSME::StateMachine *stateMachine)
MainWindow(QWidget *parent=nullptr, Qt::WindowFlags f={})
void loadPresets(const QString &presetsDir)
void setInputMode(MainWindow::InputMode mode)