Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROTOTYPE] prototype for app customization/whitelabeling via custom file #3472

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(MM_SRCS
position/mapposition.cpp
position/positiondirection.cpp
position/positionkit.cpp
appcustomisation.cpp
activelayer.cpp
activeproject.cpp
androidutils.cpp
Expand Down Expand Up @@ -123,6 +124,7 @@ set(MM_HDRS
position/mapposition.h
position/positiondirection.h
position/positionkit.h
appcustomisation.h
activelayer.h
activeproject.h
androidutils.h
Expand Down
17 changes: 17 additions & 0 deletions app/appcustomisation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "appcustomisation.h"

AppCustomisation::AppCustomisation( QObject *parent ): QObject( parent )
{
// This file will have only empty contructor in main production MM app;
// in whitelabelled apps it will have the overriden properties like AC_ORG_NAME
mValues[AC_ORG_NAME] = "blabllba";
}
48 changes: 48 additions & 0 deletions app/appcustomisation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef APPCUSTOMISATION_H
#define APPCUSTOMISATION_H

#include <QObject>
#include <QHash>
#include <QVariant>
#include <QString>
#include <QColor>

// Like this or pure string in code? If we use AC_* (like App Customization, ..)
// then at least we have here list of all entries that could be whitelabeled?
const QString AC_ORG_NAME = QStringLiteral("organizationName");

class AppCustomisation: public QObject
{
public:
explicit AppCustomisation( QObject *parent = nullptr );
Q_INVOKABLE QString value( const QString &key, const QString &defaultValue ) {return getValue<QString>(key, defaultValue);}
Q_INVOKABLE QColor color( const QString &key, const QColor &defaultValue ){return getValue<QColor>(key, defaultValue);}

// maybe for some on -off things like allow switching default server (so in the QML we can read this and do not need to patch the file)
Q_INVOKABLE bool boolean( const QString &key, bool defaultValue ){return getValue<bool>(key, defaultValue);}

private:
// Template, ou yeah!
template <typename T> T getValue(const QString &key, const T &defaultValue )
{
const auto it = mValues.find(key);
if (it == mValues.constEnd()) {
return defaultValue;
} else {
return it->value<T>();
}
}

QHash<QString, QVariant> mValues;
};

#endif // APPCUSTOMISATION_H
5 changes: 4 additions & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "test/inputtests.h"
#endif
#include <qqml.h>
#include "appcustomisation.h"
#include <qgsmessagelog.h>
#include "qgsconfig.h"
#include "qgsproviderregistry.h"
Expand Down Expand Up @@ -380,9 +381,11 @@ int main( int argc, char *argv[] )
{
QgsApplication app( argc, argv, true );

AppCustomisation appCustomisation;

const QString version = CoreUtils::appVersion();
// Set up the QSettings environment must be done after qapp is created
QCoreApplication::setOrganizationName( "Lutra Consulting" );
QCoreApplication::setOrganizationName( appCustomisation.value(AC_ORG_NAME, "Lutra Consulting") );
QCoreApplication::setOrganizationDomain( "lutraconsulting.co.uk" );
QCoreApplication::setApplicationName( "Input" ); // used by QSettings
QCoreApplication::setApplicationVersion( version );
Expand Down
11 changes: 10 additions & 1 deletion app/mmstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef MMSTYLE_H
#define MMSTYLE_H

#include "appcustomisation.h"

#include <QObject>
#include <QFont>
#include <QColor>
Expand Down Expand Up @@ -337,7 +339,7 @@ class MMStyle: public QObject
QFont p6() {return fontFactory( 12, false );}
QFont p7() {return fontFactory( 10, false );}

QColor grassColor() {return QColor::fromString( "#73D19C" );}
QColor grassColor() {return colorFactory( "grass", "#73D19C" );}
QColor forestColor() {return QColor::fromString( "#004C45" );}
QColor nightColor() {return QColor::fromString( "#12181F" );}
QColor polarColor() {return QColor::fromString( "#FFFFFF" );}
Expand Down Expand Up @@ -739,6 +741,13 @@ class MMStyle: public QObject
return f;
}

QColor colorFactory( const QString& name, const QString& color )
{
QColor defaultColor = QColor::fromString( color );
return mAppCustomisation.color(name, defaultColor);
}

AppCustomisation mAppCustomisation; // Add to constructor...
qreal mDp;

double mSafeAreaTop = 0;
Expand Down
Loading