Skip to content

Commit 2e34045

Browse files
Transform component's init and shutdown to signals
1 parent edd2254 commit 2e34045

8 files changed

Lines changed: 90 additions & 85 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,9 +2777,7 @@ if(QML)
27772777
src/qml/qmlvisibleeffectsmodel.cpp
27782778
src/qml/qmlwaveformoverview.cpp
27792779
src/qml/mixxxcontroller.cpp
2780-
src/qml/mixxxcontroller.h
27812780
src/qml/mixxxscreen.cpp
2782-
src/qml/mixxxscreen.h
27832781
# The following sources need to be in this target to get QML_ELEMENT properly interpreted
27842782
src/control/controlmodel.cpp
27852783
src/control/controlsortfiltermodel.cpp

res/controllers/Denon-DN-S3700.midi.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
</info>
88
<controller id="DN-S3700">
99
<scriptfiles>
10-
<file filename="Denon-DN-S3700.qml" functionprefix=""/>
10+
<file filename="Denon-DN-S3700.qml" />
1111
</scriptfiles>
12-
<controls />
13-
<outputs/>
1412
</controller>
1513
</MixxxControllerPreset>

res/controllers/Denon-DN-S3700.qml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import "Mixxx"
55
MixxxController {
66
id: controller
77

8-
function init() {
9-
console.error(controller.controllerId, controller.debugMode);
10-
}
11-
function shutdown() {
12-
console.error(`Shutting down ${controller.controllerId} with debug mode ${controller.debugMode}`);
13-
}
8+
onInit: console.error(`Starting controller ${controller.controllerId} with debug mode ${controller.debugMode}`)
9+
onShutdown: console.error(`Shutting down ${controller.controllerId} with debug mode ${controller.debugMode}`)
1410

1511
MixxxScreen {
1612
screenId: "screen 7"
1713
splashOff: 5000
18-
Component.onCompleted: console.error(`MixxxScreen.identifier=${screenId} ${splashOff}`)
14+
onInit: console.error(`MixxxScreen.screenId=${screenId}, MixxxScreen.splashOff=${splashOff}`)
1915
}
2016
}

src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() {
129129

130130
#ifdef MIXXX_USE_QML
131131
for (const auto& controller : m_mixxxController) {
132-
controller->shutdown();
132+
emit controller->shutdown();
133133
}
134134

135135
if (!m_bQmlMode) {
@@ -207,7 +207,7 @@ bool ControllerScriptEngineLegacy::callInitFunction() {
207207
}
208208

209209
for (const auto& controller : m_mixxxController) {
210-
controller->init();
210+
emit controller->init();
211211
}
212212

213213
QHashIterator<QString, std::shared_ptr<QQuickItem>> i(m_rootItems);
@@ -261,48 +261,7 @@ bool ControllerScriptEngineLegacy::callInitFunction() {
261261
// ControllerScriptEngineBase::handleQMLErrors
262262
}
263263

264-
QListIterator<std::shared_ptr<mixxx::qml::MixxxController>> controllers(m_mixxxController);
265-
bool controllersSuccess = true;
266-
while (controllers.hasNext()) {
267-
const QMetaObject* metaObject = controllers.next()->metaObject();
268-
269-
VERIFY_OR_DEBUG_ASSERT(metaObject) {
270-
qCWarning(m_logger) << "Invalid meta object for controller";
271-
continue;
272-
}
273-
274-
QMetaMethod initFunction;
275-
bool typed = false;
276-
int methodIdx = metaObject->indexOfMethod(kQmlComponentInitFunctionUntypedSignature);
277-
278-
if (methodIdx == -1 || !metaObject->method(methodIdx).isValid()) {
279-
qCDebug(m_logger) << "QML controller has no valid untyped init method.";
280-
methodIdx = metaObject->indexOfMethod(kQmlComponentFunctionTypedSignature);
281-
typed = true;
282-
}
283-
284-
initFunction = metaObject->method(methodIdx);
285-
286-
if (!initFunction.isValid()) {
287-
qCDebug(m_logger) << "QML controller has no valid untyped init method; Skipping.";
288-
continue;
289-
}
290-
291-
qCDebug(m_logger) << "Executing init on QML controller";
292-
if (typed) {
293-
success &= initFunction.invoke(i.value().get(),
294-
Qt::DirectConnection,
295-
Q_ARG(QString, controllerName),
296-
Q_ARG(bool, m_logger().isDebugEnabled()));
297-
} else {
298-
success &= initFunction.invoke(i.value().get(),
299-
Qt::DirectConnection,
300-
Q_ARG(QVariant, controllerName),
301-
Q_ARG(QVariant, m_logger().isDebugEnabled()));
302-
}
303-
}
304-
305-
return success && controllersSuccess;
264+
return success;
306265
}
307266
#endif
308267
}

src/qml/mixxxcontroller.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,38 @@
22

33
namespace mixxx {
44
namespace qml {
5-
void MixxxController::init() {
6-
metaObject()->invokeMethod(this, "init");
5+
6+
MixxxController::MixxxController(QObject* parent)
7+
: QObject(parent), m_pChildren(this, &m_children) {
78
}
8-
void MixxxController::shutdown() {
9-
metaObject()->invokeMethod(this, "shutdown");
9+
10+
void MixxxController::classBegin() {
1011
}
12+
13+
void MixxxController::componentComplete() {
14+
QObject::connect(this,
15+
&MixxxController::init,
16+
this,
17+
&MixxxController::initChildrenComponents);
18+
QObject::connect(this,
19+
&MixxxController::shutdown,
20+
this,
21+
&MixxxController::shutdownChildrenComponents);
22+
}
23+
24+
void MixxxController::initChildrenComponents() {
25+
for (auto* childComponent : m_children) {
26+
// Try emit init signal
27+
QMetaObject::invokeMethod(childComponent, "init", Qt::DirectConnection);
28+
}
29+
}
30+
31+
void MixxxController::shutdownChildrenComponents() {
32+
for (auto* childComponent : m_children) {
33+
// Try emit shutdown signal
34+
QMetaObject::invokeMethod(childComponent, "shutdown", Qt::DirectConnection);
35+
}
36+
}
37+
1138
} // namespace qml
1239
} // namespace mixxx

src/qml/mixxxcontroller.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,36 @@
66
#include <QObject>
77
#include <QtQml>
88

9-
#include "mixxxscreen.h"
10-
119
namespace mixxx {
1210
namespace qml {
1311

14-
class MixxxController : public QObject {
12+
class MixxxController : public QObject, public QQmlParserStatus {
1513
Q_OBJECT
14+
Q_INTERFACES(QQmlParserStatus)
1615
QML_ELEMENT
1716
Q_PROPERTY(QString controllerId MEMBER m_controllerId)
1817
Q_PROPERTY(bool debugMode MEMBER m_debugMode)
19-
Q_PROPERTY(QQmlListProperty<MixxxScreen> screens MEMBER m_screens)
20-
Q_CLASSINFO("DefaultProperty", "screens")
18+
Q_PROPERTY(QQmlListProperty<QObject> childComponents MEMBER m_pChildren)
19+
Q_CLASSINFO("DefaultProperty", "childComponents")
2120

2221
public:
22+
explicit MixxxController(QObject* parent = nullptr);
23+
void classBegin() override;
24+
void componentComplete() override;
25+
26+
signals:
2327
void init();
2428
void shutdown();
2529

2630
private:
2731
QString m_controllerId;
2832
bool m_debugMode;
29-
QQmlListProperty<MixxxScreen> m_screens;
33+
QList<QObject*> m_children;
34+
QQmlListProperty<QObject> m_pChildren;
35+
36+
private slots:
37+
void initChildrenComponents();
38+
void shutdownChildrenComponents();
3039
};
3140

3241
} // namespace qml

src/qml/mixxxscreen.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,30 @@
22

33
namespace mixxx {
44
namespace qml {
5+
6+
int MixxxScreen::width() {
7+
return m_size.width();
8+
}
9+
10+
void MixxxScreen::setWidth(int value) {
11+
m_size = QSize(value, m_size.height());
12+
}
13+
14+
int MixxxScreen::height() {
15+
return m_size.width();
16+
}
17+
18+
void MixxxScreen::setHeight(int value) {
19+
m_size = QSize(m_size.width(), value);
20+
}
21+
22+
uint MixxxScreen::splashOff() {
23+
return m_splashOff.count();
24+
}
25+
26+
void MixxxScreen::setSplashOff(uint value) {
27+
m_splashOff = std::chrono::milliseconds(value);
28+
}
29+
530
} // namespace qml
631
} // namespace mixxx

src/qml/mixxxscreen.h

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#ifndef MIXXX_MIXXXSCREEN_H
66
#define MIXXX_MIXXXSCREEN_H
77

8+
#include <QtQml/qqmlregistration.h>
9+
810
#include <QImage>
911
#include <QObject>
1012
#include <QSize>
11-
#include <QtQmlIntegration>
1213

1314
namespace mixxx {
1415
namespace qml {
@@ -34,24 +35,16 @@ class MixxxScreen : public QObject {
3435
};
3536
Q_ENUM(ColorEndian)
3637

37-
int width() {
38-
return m_size.width();
39-
}
40-
void setWidth(int value) {
41-
m_size = QSize(value, m_size.height());
42-
}
43-
int height() {
44-
return m_size.width();
45-
}
46-
void setHeight(int value) {
47-
m_size = QSize(m_size.width(), value);
48-
}
49-
uint splashOff() {
50-
return m_splashOff.count();
51-
}
52-
void setSplashOff(uint value) {
53-
m_splashOff = std::chrono::milliseconds(value);
54-
}
38+
int width();
39+
void setWidth(int value);
40+
int height();
41+
void setHeight(int value);
42+
uint splashOff();
43+
void setSplashOff(uint value);
44+
45+
signals:
46+
void init();
47+
void shutdown();
5548

5649
private:
5750
QString m_screenId; // The screen identifier.

0 commit comments

Comments
 (0)