Skip to content

Commit

Permalink
qmlui: more work on definition editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Dec 28, 2018
1 parent 4a961a9 commit ec21d56
Show file tree
Hide file tree
Showing 17 changed files with 1,084 additions and 20 deletions.
17 changes: 13 additions & 4 deletions qmlui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,10 @@ void App::createFixture()
if (m_fixtureEditor == nullptr)
{
m_fixtureEditor = new FixtureEditor(this, m_doc);
setSource(QUrl("qrc:/FixtureEditor.qml"));
//setSource(QUrl("qrc:/FixtureEditor.qml")); // another fucking segfault in QtQuick
QMetaObject::invokeMethod(rootObject(), "switchToContext",
Q_ARG(QVariant, "FXEDITOR"),
Q_ARG(QVariant, "qrc:/FixtureEditor.qml"));
}

m_fixtureEditor->createDefinition();
Expand All @@ -888,9 +891,12 @@ void App::editFixture(QString manufacturer, QString model)
if (m_fixtureEditor == nullptr)
{
m_fixtureEditor = new FixtureEditor(this, m_doc);
setSource(QUrl("qrc:/FixtureEditor.qml"));
//setSource(QUrl("qrc:/FixtureEditor.qml"));
QMetaObject::invokeMethod(rootObject(), "switchToContext",
Q_ARG(QVariant, "FXEDITOR"),
Q_ARG(QVariant, "qrc:/FixtureEditor.qml"));
}
m_doc->fixtureDefCache()->fixtureDef(manufacturer, model);
m_fixtureEditor->editDefinition(manufacturer, model);
}

void App::closeFixtureEditor()
Expand All @@ -902,6 +908,9 @@ void App::closeFixtureEditor()
}

// reload the QLC+ main view
setSource(QUrl("qrc:/MainView.qml"));
//setSource(QUrl("qrc:/MainView.qml"));
QMetaObject::invokeMethod(rootObject(), "switchToContext",
Q_ARG(QVariant, "FIXANDFUNC"),
Q_ARG(QVariant, "qrc:/FixturesAndFunctions.qml"));
}

43 changes: 42 additions & 1 deletion qmlui/fixtureeditor/editorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
*/

#include "qlcfixturedef.h"
#include "qlcchannel.h"

#include "physicaledit.h"
#include "editorview.h"

EditorView::EditorView(QQuickView *view, QLCFixtureDef *fixtureDef, QObject *parent)
: QObject(parent)
, m_view(view)
, m_fixtureDef(fixtureDef)
{

m_globalPhy = new PhysicalEdit(m_fixtureDef->physical(), this);
}

EditorView::~EditorView()
Expand Down Expand Up @@ -61,3 +63,42 @@ void EditorView::setModel(QString model)
m_fixtureDef->setModel(model);
emit modelChanged(model);
}

QString EditorView::author() const
{
return m_fixtureDef->author();
}

void EditorView::setAuthor(QString author)
{
if (m_fixtureDef->author() == author)
return;

m_fixtureDef->setAuthor(author);
emit authorChanged(author);
}

PhysicalEdit *EditorView::globalPhysical()
{
return m_globalPhy;
}

/************************************************************************
* Channels
************************************************************************/

QVariantList EditorView::channels() const
{
QVariantList list;

for (QLCChannel *channel : m_fixtureDef->channels())
{
QVariantMap chMap;
chMap.insert("mIcon", channel->getIconNameFromGroup(channel->group(), true));
chMap.insert("mLabel", channel->name());
chMap.insert("mGroup", channel->groupToString(channel->group()));
list.append(chMap);
}

return list;
}
24 changes: 24 additions & 0 deletions qmlui/fixtureeditor/editorview.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
#include <QQuickView>

class QLCFixtureDef;
class PhysicalEdit;

class EditorView : public QObject
{
Q_OBJECT

Q_PROPERTY(QString manufacturer READ manufacturer WRITE setManufacturer NOTIFY manufacturerChanged)
Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)

Q_PROPERTY(PhysicalEdit *globalPhysical READ globalPhysical CONSTANT)
Q_PROPERTY(QVariantList channels READ channels NOTIFY channelsChanged)

public:
EditorView(QQuickView *view, QLCFixtureDef* fixtureDef, QObject *parent = nullptr);
Expand All @@ -43,15 +48,34 @@ class EditorView : public QObject
QString model() const;
void setModel(QString model);

/** Get/Set the definition author */
QString author() const;
void setAuthor(QString author);

PhysicalEdit *globalPhysical();

signals:
void manufacturerChanged(QString manufacturer);
void modelChanged(QString model);
void authorChanged(QString author);

private:
/** Reference to the QML view root */
QQuickView *m_view;
/** Reference to the definition being edited */
QLCFixtureDef *m_fixtureDef;
/** Reference to the global physical properties */
PhysicalEdit *m_globalPhy;

/************************************************************************
* Channels
************************************************************************/
public:
/** Get a list of all the available channels in the definition */
QVariantList channels() const;

signals:
void channelsChanged();
};

#endif // FIXTUREEDITOR_H
38 changes: 37 additions & 1 deletion qmlui/fixtureeditor/fixtureeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@
limitations under the License.
*/

#include <QQmlContext>

#include "qlcfixturedef.h"
#include "doc.h"

#include "fixtureeditor.h"
#include "physicaledit.h"
#include "editorview.h"

FixtureEditor::FixtureEditor(QQuickView *view, Doc *doc, QObject *parent)
: QObject(parent)
, m_view(view)
, m_doc(doc)
, m_lastId(0)
{

m_view->rootContext()->setContextProperty("fixtureEditor", this);
qmlRegisterUncreatableType<EditorView>("org.qlcplus.classes", 1, 0, "EditorView", "Can't create EditorView!");
qmlRegisterUncreatableType<PhysicalEdit>("org.qlcplus.classes", 1, 0, "PhysicalEdit", "Can't create PhysicalEdit!");
}

FixtureEditor::~FixtureEditor()
Expand All @@ -36,5 +44,33 @@ FixtureEditor::~FixtureEditor()

void FixtureEditor::createDefinition()
{
m_editors[m_lastId] = new EditorView(m_view, new QLCFixtureDef());
m_lastId++;
emit editorsListChanged();
}

void FixtureEditor::editDefinition(QString manufacturer, QString model)
{
QLCFixtureDef *def = m_doc->fixtureDefCache()->fixtureDef(manufacturer, model);

m_editors[m_lastId] = new EditorView(m_view, def);
m_lastId++;
emit editorsListChanged();
}

QVariantList FixtureEditor::editorsList() const
{
QVariantList list;

QMap<int, EditorView*>::const_iterator i = m_editors.constBegin();
while (i != m_editors.constEnd())
{
QVariantMap eMap;
eMap.insert("id", i.key());
eMap.insert("cRef", QVariant::fromValue(i.value()));
list.append(eMap);
++i;
}

return list;
}
19 changes: 16 additions & 3 deletions qmlui/fixtureeditor/fixtureeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,38 @@
#include <QQuickView>

class Doc;
class QLCFixtureDef;
class EditorView;

class FixtureEditor : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList editorsList READ editorsList NOTIFY editorsListChanged)

public:
FixtureEditor(QQuickView *view, Doc *doc, QObject *parent = nullptr);
~FixtureEditor();

/** Create a new editor and an empty fixture definition */
void createDefinition();

/** Edit an existing fixture definition */
void editDefinition(QString manufacturer, QString model);

/** Returns a list of the created editors */
QVariantList editorsList() const;

signals:
void editorsListChanged();

private:
/** Reference to the QML view root */
QQuickView *m_view;
/** Reference to the project workspace */
Doc *m_doc;
/** Map of index / references to the definitions being edited */
QMap<int, QLCFixtureDef *>m_fixtures;
/** The last assigned editor ID */
int m_lastId;
/** Map of id / references to the open editors */
QMap<int, EditorView *>m_editors;
};

#endif // FIXTUREEDITOR_H

0 comments on commit ec21d56

Please sign in to comment.