Commit 386925b4 authored by Alessandro Portale's avatar Alessandro Portale

ScxmlEditor: Inline the Structure ui creation

Change-Id: If6c2380ea503202842fd0b1b067e85d9c1915958
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent e2dcdae8
......@@ -69,8 +69,7 @@ FORMS += \
$$PWD/stateproperties.ui \
$$PWD/stateview.ui \
$$PWD/statistics.ui \
$$PWD/statisticsdialog.ui \
$$PWD/structure.ui
$$PWD/statisticsdialog.ui
RESOURCES += \
$$PWD/common.qrc
......@@ -29,6 +29,5 @@
<file>images/state.png</file>
<file>images/state_color.png</file>
<file>images/statistics.png</file>
<file>images/structure.png</file>
</qresource>
</RCC>
......@@ -34,12 +34,16 @@
#include "scxmltagutils.h"
#include "scxmluifactory.h"
#include "structuremodel.h"
#include "treeview.h"
#include <QCheckBox>
#include <QKeyEvent>
#include <QLabel>
#include <QLineEdit>
#include <QRegExp>
#include <QRegExpValidator>
#include <QToolbar>
#include <QToolButton>
#include <QUndoStack>
#include <utils/utilsicons.h>
......@@ -102,17 +106,15 @@ bool StructureSortFilterProxyModel::filterAcceptsRow(int source_row, const QMode
Structure::Structure(QWidget *parent)
: QFrame(parent)
{
m_ui.setupUi(this);
m_ui.m_checkboxButton->setIcon(Utils::Icons::FILTER.icon());
createUi();
addCheckbox(tr("Common states"), State);
addCheckbox(tr("Metadata"), Metadata);
addCheckbox(tr("Other tags"), OnEntry);
addCheckbox(tr("Unknown tags"), UnknownTag);
m_ui.m_tagVisibilityFrame->setVisible(false);
connect(m_ui.m_checkboxButton, &QToolButton::toggled, m_ui.m_tagVisibilityFrame, &QFrame::setVisible);
m_tagVisibilityFrame->setVisible(false);
connect(m_checkboxButton, &QToolButton::toggled, m_tagVisibilityFrame, &QFrame::setVisible);
m_model = new StructureModel(this);
......@@ -123,15 +125,15 @@ Structure::Structure(QWidget *parent)
// Default set of the visible tags
QVector<TagType> visibleTags;
for (int i = 0; i < Finalize; ++i)
visibleTags << (TagType)i;
visibleTags << TagType(i);
m_proxyModel->setVisibleTags(visibleTags);
m_ui.m_structureView->setModel(m_proxyModel);
m_ui.m_structureView->setItemDelegate(new TreeItemDelegate(this));
m_structureView->setModel(m_proxyModel);
m_structureView->setItemDelegate(new TreeItemDelegate(this));
connect(m_ui.m_structureView, &TreeView::pressed, this, &Structure::rowActivated);
connect(m_ui.m_structureView, &TreeView::rightButtonClicked, this, &Structure::showMenu);
connect(m_ui.m_structureView, &TreeView::entered, this, &Structure::rowEntered);
connect(m_structureView, &TreeView::pressed, this, &Structure::rowActivated);
connect(m_structureView, &TreeView::rightButtonClicked, this, &Structure::showMenu);
connect(m_structureView, &TreeView::entered, this, &Structure::rowEntered);
connect(m_model, &StructureModel::selectIndex, this, &Structure::currentTagChanged);
connect(m_model, &StructureModel::childAdded, this, &Structure::childAdded);
......@@ -145,7 +147,7 @@ void Structure::addCheckbox(const QString &name, TagType type)
box->setCheckable(true);
box->setChecked(true);
connect(box, &QCheckBox::clicked, this, &Structure::updateCheckBoxes);
m_ui.m_checkboxLayout->addWidget(box);
m_checkboxFrame->layout()->addWidget(box);
m_checkboxes << box;
}
......@@ -154,7 +156,7 @@ void Structure::updateCheckBoxes()
QVector<TagType> visibleTags;
foreach (QCheckBox *box, m_checkboxes) {
if (box->isChecked()) {
switch ((TagType)box->property(Constants::C_SCXMLTAG_TAGTYPE).toInt()) {
switch (TagType(box->property(Constants::C_SCXMLTAG_TAGTYPE).toInt())) {
case State:
visibleTags << Initial << Final << History << State << Parallel << Transition << InitialTransition;
break;
......@@ -183,13 +185,13 @@ void Structure::setDocument(ScxmlDocument *document)
m_currentDocument = document;
m_model->setDocument(document);
m_proxyModel->invalidate();
m_ui.m_structureView->expandAll();
m_structureView->expandAll();
}
void Structure::setGraphicsScene(GraphicsScene *scene)
{
m_scene = scene;
connect(m_ui.m_structureView, &TreeView::mouseExited, m_scene, &GraphicsScene::unhighlightAll);
connect(m_structureView, &TreeView::mouseExited, m_scene, &GraphicsScene::unhighlightAll);
}
void Structure::rowEntered(const QModelIndex &index)
......@@ -221,7 +223,7 @@ void Structure::currentTagChanged(const QModelIndex &sourceIndex)
{
QModelIndex ind = m_proxyModel->mapFromSource(sourceIndex);
if (ind.isValid())
m_ui.m_structureView->setCurrentIndex(ind);
m_structureView->setCurrentIndex(ind);
}
void Structure::childAdded(const QModelIndex &childIndex)
......@@ -229,15 +231,15 @@ void Structure::childAdded(const QModelIndex &childIndex)
m_proxyModel->invalidate();
QModelIndex ind = m_proxyModel->mapFromSource(childIndex);
if (ind.isValid()) {
m_ui.m_structureView->setCurrentIndex(ind);
m_ui.m_structureView->expand(ind.parent());
m_structureView->setCurrentIndex(ind);
m_structureView->expand(ind.parent());
}
}
void Structure::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Delete) {
QModelIndex ind = m_proxyModel->mapToSource(m_ui.m_structureView->currentIndex());
QModelIndex ind = m_proxyModel->mapToSource(m_structureView->currentIndex());
auto tag = static_cast<ScxmlTag*>(ind.internalPointer());
if (tag && m_currentDocument) {
m_currentDocument->undoStack()->beginMacro(tr("Remove items"));
......@@ -248,6 +250,49 @@ void Structure::keyPressEvent(QKeyEvent *e)
QFrame::keyPressEvent(e);
}
void Structure::createUi()
{
auto titleLabel = new QLabel(tr("Structure"));
titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
m_checkboxButton = new QToolButton;
m_checkboxButton->setIcon(Utils::Icons::FILTER.icon());
m_checkboxButton->setCheckable(true);
auto toolBar = new QToolBar;
toolBar->addWidget(titleLabel);
toolBar->addWidget(m_checkboxButton);
m_structureView = new TreeView;
m_visibleTagsTitle = new QLabel;
m_checkboxFrame = new QWidget;
m_checkboxFrame->setLayout(new QVBoxLayout);
m_checkboxFrame->layout()->setMargin(0);
auto spacer = new QWidget;
spacer->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
m_tagVisibilityFrame = new QWidget;
m_tagVisibilityFrame->setLayout(new QVBoxLayout);
m_tagVisibilityFrame->layout()->addWidget(m_visibleTagsTitle);
m_tagVisibilityFrame->layout()->addWidget(m_checkboxFrame);
m_tagVisibilityFrame->layout()->addWidget(spacer);
m_tagVisibilityFrame->layout()->setMargin(0);
auto paneInnerFrame = new QWidget;
paneInnerFrame->setLayout(new QHBoxLayout);
paneInnerFrame->layout()->addWidget(m_structureView);
paneInnerFrame->layout()->addWidget(m_tagVisibilityFrame);
paneInnerFrame->layout()->setMargin(0);
setLayout(new QVBoxLayout);
layout()->addWidget(toolBar);
layout()->addWidget(paneInnerFrame);
layout()->setMargin(0);
layout()->setSpacing(0);
}
void Structure::showMenu(const QModelIndex &index, const QPoint &globalPos)
{
if (index.isValid()) {
......@@ -255,8 +300,8 @@ void Structure::showMenu(const QModelIndex &index, const QPoint &globalPos)
auto tag = static_cast<ScxmlTag*>(ind.internalPointer());
if (tag) {
auto menu = new QMenu;
menu->addAction(tr("Expand All"), m_ui.m_structureView, &TreeView::expandAll);
menu->addAction(tr("Collapse All"), m_ui.m_structureView, &TreeView::collapseAll);
menu->addAction(tr("Expand All"), m_structureView, &TreeView::expandAll);
menu->addAction(tr("Collapse All"), m_structureView, &TreeView::collapseAll);
menu->addSeparator();
menu->addAction(m_scene->actionHandler()->action(ActionCopy));
menu->addAction(m_scene->actionHandler()->action(ActionPaste));
......@@ -285,7 +330,7 @@ void Structure::showMenu(const QModelIndex &index, const QPoint &globalPos)
tag->document()->undoStack()->beginMacro(tr("Add child"));
ScxmlTag *childTag = SceneUtils::addChild(tag, data, m_scene);
if (childTag && childTag->tagType() <= MetadataItem)
m_ui.m_structureView->edit(m_ui.m_structureView->currentIndex());
m_structureView->edit(m_structureView->currentIndex());
tag->document()->undoStack()->endMacro();
}
}
......
......@@ -33,6 +33,9 @@
QT_FORWARD_DECLARE_CLASS(QCheckBox)
QT_FORWARD_DECLARE_CLASS(QKeyEvent)
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QToolbar)
QT_FORWARD_DECLARE_CLASS(QToolButton)
namespace ScxmlEditor {
......@@ -84,6 +87,7 @@ protected:
void keyPressEvent(QKeyEvent *e) override;
private:
void createUi();
void rowActivated(const QModelIndex &index);
void rowEntered(const QModelIndex &index);
void childAdded(const QModelIndex &index);
......@@ -99,6 +103,14 @@ private:
QVector<QCheckBox*> m_checkboxes;
TreeItemDelegate *m_customDelegate = nullptr;
Ui::Structure m_ui;
QWidget *m_paneInnerFrame = nullptr;
TreeView *m_structureView = nullptr;
QToolButton *m_checkboxButton = nullptr;
QLabel *m_visibleTagsTitle = nullptr;
QWidget *m_tagVisibilityFrame = nullptr;
QWidget *m_checkboxFrame = nullptr;
QLayout *m_checkboxLayout = nullptr;
};
} // namespace Common
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScxmlEditor::Common::Structure</class>
<widget class="QFrame" name="ScxmlEditor::Common::Structure">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>425</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="m_titleFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="m_icon">
<property name="minimumSize">
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>28</width>
<height>28</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="common.qrc">:/scxmleditor/images/structure.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_title">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Structure</string>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_checkboxButton">
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="m_paneInnerFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>1</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ScxmlEditor::Common::TreeView" name="m_structureView">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="indentation">
<number>20</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>50</number>
</attribute>
</widget>
</item>
<item>
<widget class="QFrame" name="m_tagVisibilityFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>1</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="m_visibleTagsTitle">
<property name="text">
<string>Visible Tags</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="m_checkboxFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="m_checkboxLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<extends>QTreeView</extends>
<header>treeview.h</header>
<class>ScxmlEditor::Common::TreeView</class>
</customwidget>
</customwidgets>
<resources>
<include location="common.qrc"/>
</resources>
<connections/>
</ui>
......@@ -39,6 +39,8 @@ TreeView::TreeView(QWidget *parent)
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::DragDrop);
setMouseTracking(true);
setFrameShape(QFrame::NoFrame);
setHeaderHidden(true);
}
void TreeView::leaveEvent(QEvent *e)
......
......@@ -81,7 +81,6 @@ QtcPlugin {
"stateview.ui",
"statistics.ui",
"statisticsdialog.ui",
"structure.ui",
]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment