Skip to content

Commit

Permalink
Load and launch QQmlApplicationEngine from main() rather than RadioIn…
Browse files Browse the repository at this point in the history
…terface

Appropriate changes have been made to the RadioInterface and QML files
  • Loading branch information
viktorgino committed Feb 15, 2017
1 parent 728f2e9 commit c5b37b8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 115 deletions.
6 changes: 3 additions & 3 deletions gui/QML/InfoPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Item {

TextStandart {
id: showVersionText
text: "welle.io version"
text: cppGUI.licenses.version
Layout.alignment: Qt.AlignLeft
objectName: "showVersionText"
}
Expand All @@ -40,7 +40,7 @@ Item {

TextStandart {
id: showGraphLicense
text: "showGraphLicense"
text: cppGUI.licenses.graphLicense
Layout.alignment: Qt.AlignLeft
objectName: "showGraphLicense"
wrapMode: Text.Wrap
Expand All @@ -50,7 +50,7 @@ Item {

TextStandart {
id: showLicenseText
text: "showLicenseText"
text: cppGUI.licenses.license
Layout.alignment: Qt.AlignLeft
objectName: "showLicenseText"
wrapMode: Text.WrapAnywhere
Expand Down
7 changes: 6 additions & 1 deletion gui/QML/SettingsPage.qml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0

// Import custom styles
import "style"

Item {
id: settingsPage

property alias showChannelState : enableExpertMode.checked
property alias enableFullScreenState : enableFullScreen.checked
property alias enableExpertModeState : enableExpertMode.checked

Settings {
property alias enableFullScreenState : settingsPage.enableFullScreenState
property alias enableExpertModeState : settingsPage.enableExpertModeState
}

Connections{
target: cppGUI
onChannelScanStopped:{
Expand Down
13 changes: 9 additions & 4 deletions gui/QML/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0

// Import custom styles
import "style"
Expand All @@ -53,6 +54,10 @@ ApplicationWindow {
height: Units.dp(500)
visibility: settingsPageLoader.settingsPage.enableFullScreenState ? "FullScreen" : "Windowed"

Settings {
property alias width : mainWindow.width
property alias height : mainWindow.height
}
Loader {
id: settingsPageLoader
anchors.topMargin: Units.dp(10)
Expand Down Expand Up @@ -189,12 +194,12 @@ ApplicationWindow {
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
model: stationModel
model: cppGUI.stationModel
anchors.fill: parent
delegate: StationDelegate {
stationNameText: stationName
channelNameText: channelName
onClicked: cppGUI.channelClick(stationName, channelName)
stationNameText: modelData.stationName
channelNameText: modelData.channelName
onClicked: cppGUI.channelClick(modelData.stationName, modelData.channelName)
}
}
}
Expand Down
141 changes: 38 additions & 103 deletions gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ RadioInterface::RadioInterface(QSettings *Si,
int16_t latency = dabSettings -> value("latency", 1). toInt(); // latency is used to allow different settings for different situations wrt the output buffering
threshold = dabSettings -> value("threshold", 3). toInt(); // threshold is used in the phaseReference class as threshold for checking the validity of the correlation result
autoStart = dabSettings -> value("autoStart", 0). toInt() != 0;
int WindowHeight = dabSettings -> value("WindowHeight", 0). toInt();
int WindowWidth = dabSettings -> value("WindowWidth", 0). toInt();
bool isFullscreen = dabSettings -> value("StartInFullScreen", false). toBool();
bool isExpertMode = dabSettings-> value("EnableExpertMode", false). toBool();

// Read channels from the settings
dabSettings -> beginGroup("channels");
Expand All @@ -88,68 +84,11 @@ RadioInterface::RadioInterface(QSettings *Si,
dabSettings -> endGroup();
stationList. sort();

// Create new QML application, set some requried options and load the QML file
engine = new QQmlApplicationEngine;
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("cppGUI", this);
rootContext -> setContextProperty("stationModel", QVariant::fromValue(stationList.getList()));
engine->load(QUrl("qrc:/QML/main.qml"));
QObject *rootObject = engine -> rootObjects().first();

// Set some properties
if(WindowHeight != 0) rootObject -> setProperty ("height", WindowHeight);
if(WindowWidth != 0)rootObject -> setProperty ("width", WindowWidth);
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();

// Add image provider for the MOT slide show
MOTImage = new MOTImageProvider;
engine->addImageProvider(QLatin1String("motslideshow"), MOTImage);


// Restore the full screen property
QObject *enableFullScreenObject = rootObject -> findChild<QObject*> ("enableFullScreen");
if(enableFullScreenObject != NULL)
enableFullScreenObject -> setProperty("checked", isFullscreen);

// Restore expert mode
QObject *expertModeObject = rootObject -> findChild<QObject*> ("enableExpertMode");
if(expertModeObject != NULL)
expertModeObject -> setProperty("checked", isExpertMode);

// Set application version
QObject *showVersionTextObject = rootObject -> findChild<QObject*> ("showVersionText");
if(showVersionTextObject != NULL)
{
QString InfoText;
InfoText += "welle.io version: " + QString(CURRENT_VERSION) + "\n";
InfoText += "Build on: " + QString(__TIMESTAMP__);
showVersionTextObject -> setProperty("text", InfoText);
}

// Set graph license
QObject *showGraphLicenseObject = rootObject -> findChild<QObject*> ("showGraphLicense");
if(showGraphLicenseObject != NULL)
{
// Read license
QFile File(":/QML/images/NOTICE.txt");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set license content
showGraphLicenseObject -> setProperty("text", FileContent);
}

// Set license
QObject *showLicenseTextObject = rootObject -> findChild<QObject*> ("showLicenseText");
if(showLicenseTextObject != NULL)
{
// Read license
QFile File(":/license");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set license content
showLicenseTextObject -> setProperty("text", FileContent);
}

// the name of the device is passed on from the main program
if(!setDevice(input_device))
Expand Down Expand Up @@ -205,6 +144,34 @@ RadioInterface::~RadioInterface()
{
fprintf(stderr, "deleting radioInterface\n");
}
/**
* \brief returns the licenses for all the relative libraries plus application version information
*/
const QVariantMap RadioInterface::licenses(){
QVariantMap ret;
// Set application version
QString InfoText;
InfoText += "welle.io version: " + QString(CURRENT_VERSION) + "\n";
InfoText += "Build on: " + QString(__TIMESTAMP__);
ret.insert("version", InfoText);

// Read graph license
QFile File(":/QML/images/NOTICE.txt");
File.open(QFile::ReadOnly);
QByteArray FileContent = File.readAll();

// Set graph license content
ret.insert("graphLicense", FileContent);

// Read license
QFile File2(":/license");
File2.open(QFile::ReadOnly);
QByteArray FileContent2 = File2.readAll();

// Set license content
ret.insert("license", FileContent2);
return ret;
}

/**
* \brief At the end, we might save some GUI values
Expand All @@ -231,37 +198,6 @@ void RadioInterface::dumpControlState(QSettings *s)
s -> setValue("channel/" + QString::number(i),
stationList. getStationAt(i - 1));
dabSettings -> endGroup();

// Read settings from GUI
// Take the root object
QObject *rootObject = engine -> rootObjects(). first();

// Save the windows properties
int WindowWidth = rootObject -> property("width"). toInt();
s -> setValue("WindowWidth", WindowWidth);
int WindowHeight = rootObject -> property("height"). toInt();
s -> setValue("WindowHeight", WindowHeight);
// Access the full screen mode switch
QObject *enableFullScreenObject =
rootObject -> findChild<QObject*>("enableFullScreen");
if(enableFullScreenObject != NULL)
{
bool isFullScreen =
enableFullScreenObject -> property("checked").toBool();
// Save the setting
s -> setValue("StartInFullScreen", isFullScreen);
}

// Access to the enable expert mode switch
QObject *expertModeObject =
rootObject -> findChild<QObject*> ("enableExpertMode");
if(expertModeObject != NULL)
{
bool isExpertMode =
expertModeObject->property("checked"). toBool();
// Save the setting
s -> setValue("EnableExpertMode", isExpertMode);
}
}
//
/// the values for the different Modes:
Expand Down Expand Up @@ -719,11 +655,11 @@ void RadioInterface::stopChannelScanClick(void)
scanMode = false;

emit currentStation("No Station");

// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
}

QString RadioInterface::nextChannel(QString currentChannel)
Expand Down Expand Up @@ -763,9 +699,9 @@ void RadioInterface::setSignalPresent(bool isSignal)
emit currentStation("No Station");
// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));

p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
return;
}
set_channelSelect(currentChannel);
Expand Down Expand Up @@ -793,9 +729,8 @@ void RadioInterface::end_of_waiting_for_stations(void)
emit currentStation("No Station");
// Sort stations
stationList. sort();
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("stationModel",
QVariant::fromValue(stationList. getList()));
p_stationModel = QVariant::fromValue(stationList.getList());
emit stationModelChanged();
return;
}
set_channelSelect(currentChannel);
Expand Down
14 changes: 11 additions & 3 deletions gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <QQmlContext>

#include <QtCharts>
#include <QList>
using namespace QtCharts;

#include "stationlist.h"
Expand Down Expand Up @@ -73,7 +74,9 @@ typedef enum {
* QDialog and the generated form
*/
class RadioInterface: public QObject{
Q_OBJECT
Q_OBJECT
Q_PROPERTY(QVariant stationModel READ stationModel NOTIFY stationModelChanged)
Q_PROPERTY(QVariant licenses READ licenses CONSTANT)

public:
RadioInterface (QSettings *,
Expand All @@ -89,10 +92,13 @@ Q_OBJECT
Q_INVOKABLE void inputEnableAGCChange (bool checked);
Q_INVOKABLE void inputGainChange (double gain);
Q_INVOKABLE void terminateProcess (void);
QVariant stationModel() const {
return p_stationModel;
}
MOTImageProvider *MOTImage;

private:
QSettings *dabSettings;
QQmlApplicationEngine *engine;
bool autoStart;
int16_t threshold;
void setModeParameters (uint8_t);
Expand All @@ -108,6 +114,7 @@ Q_OBJECT
RingBuffer<int16_t> *audioBuffer;
common_fft *spectrum_fft_handler;
bool autoCorrector;
const QVariantMap licenses();
const char *get_programm_type_string (uint8_t);
const char *get_programm_language_string (uint8_t);
void dumpControlState (QSettings *);
Expand All @@ -132,10 +139,10 @@ const char *get_programm_language_string (uint8_t);
bool setDevice (QString);
QString nextChannel (QString currentChannel);
QString input_device;
MOTImageProvider *MOTImage;
int32_t tunedFrequency;
int LastCurrentManualGain;
int CurrentFrameErrors;
QVariant p_stationModel;

public slots:
void end_of_waiting_for_stations (void);
Expand Down Expand Up @@ -200,6 +207,7 @@ private slots:
void displayRSErrors (int Errors);
void displayAACErrors (int Errors);
void showErrorMessage (QString Text);
void stationModelChanged ();
};

#endif
Expand Down
12 changes: 11 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,17 @@ uint16_t ipPort = 1234;

#if QT_VERSION >= 0x050600
QGuiApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
#endif
#endif

QQmlApplicationEngine *engine;

// Create new QML application, set some requried options and load the QML file
engine = new QQmlApplicationEngine;
QQmlContext *rootContext = engine -> rootContext();
rootContext -> setContextProperty("cppGUI", MyRadioInterface);
engine->load(QUrl("qrc:/QML/main.qml"));
engine->addImageProvider(QLatin1String("motslideshow"), MyRadioInterface->MOTImage);

a. exec ();
/*
* done:
Expand Down

0 comments on commit c5b37b8

Please sign in to comment.