1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 10:42:29 +01:00

Remove QGuiApplication pointer to classes. This is not needed because we can call the static method QGuiApplication::instance() everywhere

Remove QSettings init because it is created after setting organization name url etc. See QSettings::QSettings(QObject *parent = nullptr) in the docs for more info
This commit is contained in:
Elias 2019-02-15 11:58:38 +01:00
parent 476d1b6a34
commit bb9db9117a
7 changed files with 36 additions and 43 deletions

View File

@ -1,4 +1,3 @@
#include <QDebug>
#include <QDir>
#include <QFontDatabase>
#include <QGuiApplication>
@ -9,13 +8,8 @@
#include <QQmlEngine>
#include <QStringList>
#include <QUrl>
#include <QtGlobal>
#include <QtWebEngine>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
#include "src/create.h"
#include "src/installedlistfilter.h"
#include "src/installedlistmodel.h"
@ -36,6 +30,7 @@ int main(int argc, char* argv[])
QGuiApplication::setApplicationVersion("0.2.0");
QGuiApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
app.setWindowIcon(QIcon(":/assets/icons/favicon.ico"));
@ -55,15 +50,15 @@ int main(int argc, char* argv[])
QMLUtilities qmlUtil;
InstalledListModel installedListModel;
InstalledListFilter installedListFilter(&installedListModel);
MonitorListModel monitorListModel(&app);
MonitorListModel monitorListModel;
ProfileListModel profileListModel;
SDKConnector sdkConnector;
// Create settings in the end because for now it depends on
// such things as the profile list model to complete
// It will also set the m_absoluteStoragePath in profileListModel and installedListModel
Settings settings(&profileListModel, &monitorListModel, &installedListModel, &sdkConnector, &app);
ScreenPlay screenPlay(&installedListModel, &settings, &monitorListModel, &app, &sdkConnector);
Settings settings(&profileListModel, &monitorListModel, &installedListModel, &sdkConnector);
ScreenPlay screenPlay(&installedListModel, &settings, &monitorListModel, &sdkConnector);
Create create(&settings, &qmlUtil);
// All the list need the default path from the settings

View File

@ -1,17 +1,17 @@
#include "monitorlistmodel.h"
MonitorListModel::MonitorListModel(QGuiApplication* guiapp, QObject* parent)
MonitorListModel::MonitorListModel(QObject* parent)
: QAbstractListModel(parent)
{
loadMonitors();
m_qGuiApplication = guiapp;
m_qGuiApplication = static_cast<QGuiApplication*>(QGuiApplication::instance());
connect(m_qGuiApplication, &QGuiApplication::screenAdded, this, &MonitorListModel::screenAdded);
connect(m_qGuiApplication, &QGuiApplication::screenRemoved, this, &MonitorListModel::screenRemoved);
}
QHash<int, QByteArray> MonitorListModel::roleNames() const
{
static const QHash<int, QByteArray> roles{
static const QHash<int, QByteArray> roles {
{ IDRole, "monitorID" },
{ NameRole, "monitorName" },
{ SizeRole, "monitorSize" },
@ -126,7 +126,6 @@ int MonitorListModel::size()
void MonitorListModel::wallpaperRemoved()
{
}
bool MonitorListModel::getMonitorListItemAt(int position, Monitor* monitor)
@ -163,17 +162,17 @@ void MonitorListModel::reset()
void MonitorListModel::setWallpaperActiveMonitor(QScreen* screen, QString fullPreviewImagePath)
{
// qDebug() << fullPreviewImagePath;
// for (int i = 0; i < m_monitorList.size(); ++i) {
// if (m_monitorList.at(i).m_screen == screen) {
// m_monitorList[i].m_wallpaperPreviewPath = fullPreviewImagePath;
// }
// }
// beginResetModel();
// endResetModel();
// qDebug() << fullPreviewImagePath;
// for (int i = 0; i < m_monitorList.size(); ++i) {
// if (m_monitorList.at(i).m_screen == screen) {
// m_monitorList[i].m_wallpaperPreviewPath = fullPreviewImagePath;
// }
// }
// beginResetModel();
// endResetModel();
for (int i = 0; i < m_qGuiApplication->screens().length(); ++i) {
if(m_qGuiApplication->screens().at(i) == screen){
emit setNewActiveMonitor(i,fullPreviewImagePath);
if (m_qGuiApplication->screens().at(i) == screen) {
emit setNewActiveMonitor(i, fullPreviewImagePath);
}
}
//emit monitorReloadCompleted();

View File

@ -25,7 +25,7 @@ class MonitorListModel : public QAbstractListModel {
Q_OBJECT
public:
explicit MonitorListModel(QGuiApplication* guiapp, QObject* parent = nullptr);
explicit MonitorListModel(QObject* parent = nullptr);
QHash<int, QByteArray> roleNames() const override;

View File

@ -1,12 +1,12 @@
#include "screenplay.h"
ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, QGuiApplication* qGuiApplication, SDKConnector* sdkc, QObject* parent)
ScreenPlay::ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent)
: QObject(parent)
{
m_ilm = ilm;
m_settings = set;
m_mlm = mlm;
m_qGuiApplication = qGuiApplication;
m_qGuiApplication = static_cast<QGuiApplication*>(QGuiApplication::instance());
m_sdkc = sdkc;
}
@ -19,7 +19,7 @@ void ScreenPlay::createWallpaper(int monitorIndex, QUrl absoluteStoragePath, QSt
}
// Remove previous wallpaper
//removeWallpaperAt(monitorIndex);
removeWallpaperAt(monitorIndex);
m_settings->increaseActiveWallpaperCounter();
QVector<int> tmpMonitorIndex;
@ -96,9 +96,10 @@ void ScreenPlay::setAllWallpaperValue(QString key, QString value)
void ScreenPlay::removeWallpaperAt(int at)
{
Q_ASSERT(at < m_screenPlayWallpaperList.size());
// if(m_screenPlayWallpaperList.isEmpty())
// return;
//Q_ASSERT(m_screenPlayWallpaperList.size() < at);
if (m_screenPlayWallpaperList.isEmpty())
return;
for (int i = 0; i < m_screenPlayWallpaperList.length(); ++i) {

View File

@ -27,7 +27,7 @@ class ScreenPlayWidget;
class ScreenPlay : public QObject {
Q_OBJECT
public:
explicit ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, QGuiApplication* qGuiApplication, SDKConnector* sdkc, QObject* parent = nullptr);
explicit ScreenPlay(InstalledListModel* ilm, Settings* set, MonitorListModel* mlm, SDKConnector* sdkc, QObject* parent = nullptr);
Settings* settings() const;
@ -94,7 +94,7 @@ public:
m_appID = parent->generateID();
proArgs.append("appID=" + m_appID);
proArgs.append(parent->m_settings->decoder());
proArgs.append(QString::number(volume));
proArgs.append(QString::number(static_cast<double>(volume)));
proArgs.append(fillMode);
qDebug() << proArgs;
@ -138,7 +138,6 @@ signals:
void previewImageChanged(QString previewImage);
void projectSettingsListModelAt(ProjectSettingsListModel* li);
void appIDChanged(QString appID);
void typeChanged(QString type);
public slots:
@ -229,9 +228,8 @@ public:
m_process->setProgram(parent->m_settings->getScreenPlayWidgetPath().path());
}
qDebug() << m_process->program();
connect(m_process,&QProcess::errorOccurred, this, [](QProcess::ProcessError error){
connect(m_process, &QProcess::errorOccurred, this, [](QProcess::ProcessError error) {
qDebug() << "error: " << error;
});
m_process->start();
}

View File

@ -2,17 +2,16 @@
#include <QGuiApplication>
#include <QStandardPaths>
Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QGuiApplication* app, QObject* parent)
Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QObject* parent)
: QObject(parent)
, m_version(QVersionNumber(0, 0, 1))
, m_qSettings(QSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, app->organizationName(), app->applicationName()))
{
m_plm = plm;
m_mlm = mlm;
m_ilm = ilm;
m_sdkc = sdkc;
m_app = app;
m_app = static_cast<QGuiApplication*>(QGuiApplication::instance());
if (m_qSettings.value("language").isNull()) {
auto locale = QLocale::system().uiLanguages();
@ -25,13 +24,13 @@ Settings::Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListMo
m_translator.load(":/translations/ScreenPlay_" + localeSplits.at(0) + ".qm");
m_qSettings.setValue("language", QVariant(localeSplits.at(0)));
m_qSettings.sync();
app->installTranslator(&m_translator);
m_app->installTranslator(&m_translator);
}
} else {
QFile tsFile;
if (tsFile.exists(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm")) {
m_translator.load(":/translations/ScreenPlay_" + m_qSettings.value("language").toString() + ".qm");
app->installTranslator(&m_translator);
m_app->installTranslator(&m_translator);
}
}

View File

@ -3,6 +3,7 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QGuiApplication>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
@ -11,7 +12,6 @@
#include <QProcess>
#include <QProcessEnvironment>
#include <QQmlPropertyMap>
#include <QtConcurrent/QtConcurrent>
#include <QSettings>
#include <QSharedPointer>
#include <QStandardPaths>
@ -21,8 +21,9 @@
#include <QUrl>
#include <QVariant>
#include <QVector>
#include <QtGlobal>
#include <QVersionNumber>
#include <QtConcurrent/QtConcurrent>
#include <QtGlobal>
#include "installedlistmodel.h"
#include "monitorlistmodel.h"
@ -50,7 +51,7 @@ class Settings : public QObject {
Q_OBJECT
public:
explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QGuiApplication* app, QObject* parent = nullptr);
explicit Settings(ProfileListModel* plm, MonitorListModel* mlm, InstalledListModel* ilm, SDKConnector* sdkc, QObject* parent = nullptr);
~Settings();
Q_PROPERTY(QVersionNumber version READ version)