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

Translate all RibbonButtons dynamically #5653

Merged
Merged
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
4 changes: 2 additions & 2 deletions Desktop/modules/analysisentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
namespace Modules
{

AnalysisEntry::AnalysisEntry(std::function<void ()> specialFunc, std::string internalTitle, std::string menuTitle, bool requiresData, std::string icon)
: _title(internalTitle), _function(internalTitle), _menu(menuTitle), _isSeparator(false), _isGroupTitle(!specialFunc), _requiresData(requiresData), _icon(icon), _specialFunc(specialFunc)
AnalysisEntry::AnalysisEntry(std::function<void ()> specialFunc, std::string internalTitle, std::function<std::string()> menuTitleF, bool requiresData, std::string icon)
: _title(internalTitle), _function(internalTitle), _menuF(menuTitleF), _isSeparator(false), _isGroupTitle(!specialFunc), _requiresData(requiresData), _icon(icon), _specialFunc(specialFunc)
{}

AnalysisEntry::AnalysisEntry(std::string menuTitle, std::string icon, bool smallIcon)
Expand Down
33 changes: 17 additions & 16 deletions Desktop/modules/analysisentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class AnalysisEntry
{
friend EntryBase;
public:
AnalysisEntry(std::function<void()> specialFunc, std::string internalTitle, std::string menuTitle, bool requiresData=true, std::string icon = ""); ///< AnalysisEntry with a callbackfunction to JASP, if !specialFunc then a grouptitle
AnalysisEntry(std::function<void()> specialFunc, std::string internalTitle, std::function<std::string()> menuTitleF, bool requiresData=true, std::string icon = ""); ///< AnalysisEntry with a callbackfunction to JASP, if !specialFunc then a grouptitle
AnalysisEntry(std::string menuTitle, std::string icon = "", bool small=false); ///< AnalysisEntry grouptitle
AnalysisEntry(Json::Value & analysisEntry, DynamicModule * dynamicModule, bool defaultRequiresData = true); ///< AnalysisEntry from a modules Description.qml
AnalysisEntry(); ///< AnalysisEntry separator

std::string menu() const { return _menu; }
std::string menu() const { return _menuF ? _menuF() : _menu; }
std::string title() const { return _title; }
std::string function() const { return _function; }
std::string qml() const { return _qml != "" ? _qml : _function + ".qml"; }
Expand Down Expand Up @@ -75,20 +75,21 @@ class AnalysisEntry
static bool requiresDataEntries(const AnalysisEntries & entries);

private:
std::string _title = "???" ,
_function = "???" ,
_qml = "???" ,
_menu = "???" ,
_icon = "" ;
DynamicModule* _dynamicModule = nullptr ;
bool _isSeparator = true ,
_isGroupTitle = false ,
_isAnalysis = false ,
_isEnabled = true ,
_requiresData = true ,
_hasWrapper = false ,
_smallIcon = false ;
std::function<void()> _specialFunc = nullptr ;
std::string _title = "???" ,
_function = "???" ,
_qml = "???" ,
_menu = "???" ,
_icon = "" ;
DynamicModule* _dynamicModule = nullptr ;
bool _isSeparator = true ,
_isGroupTitle = false ,
_isAnalysis = false ,
_isEnabled = true ,
_requiresData = true ,
_hasWrapper = false ,
_smallIcon = false ;
std::function<void()> _specialFunc = nullptr ;
std::function<std::string()> _menuF = nullptr ; //To make it translatable
};

}
Expand Down
24 changes: 15 additions & 9 deletions Desktop/modules/ribbonbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//

#include "ribbonbutton.h"
#include "enginedefinitions.h"
#include "modules/dynamicmodule.h"
#include "modules/analysisentry.h"
#include "utilities/qutils.h"
Expand Down Expand Up @@ -49,31 +48,31 @@ RibbonButton::RibbonButton(QObject *parent, DynamicModule * module) : QObject(p
bindYourself();
}

RibbonButton::RibbonButton(QObject *parent, std::string name, std::string title, std::string icon, bool requiresData, std::function<void ()> justThisFunction, std::string toolTip, bool enabled, bool remember, bool defaultActiveBinding)
RibbonButton::RibbonButton(QObject *parent, std::string name, std::function<std::string()> titleF, std::string icon, bool requiresData, std::function<void ()> justThisFunction, std::function<QString()> toolTipF, bool enabled, bool remember, bool defaultActiveBinding)
: QObject(parent), _enabled(enabled), _defaultActiveBinding(defaultActiveBinding), _remember(remember), _special(true), _module(nullptr), _specialButtonFunc(justThisFunction)
{
_menuModel = new MenuModel(this);

setModuleName(name);
setTitle(title);
setToolTip(tq(toolTip));
_titleF = titleF;
_toolTipF = toolTipF;
setIconSource(tq(icon));

setRequiresData(requiresData); //setRequiresData because setMenu changes it based on the menu entries, but that doesnt work for this special dummy

bindYourself();
}

RibbonButton::RibbonButton(QObject *parent, std::string name, std::string title, std::string icon, Modules::AnalysisEntries * funcEntries, std::string toolTip, bool enabled, bool remember, bool defaultActiveBinding)
RibbonButton::RibbonButton(QObject *parent, std::string name, std::function<std::string()> titleF, std::string icon, Modules::AnalysisEntries * funcEntries, std::function<QString()> toolTipF, bool enabled, bool remember, bool defaultActiveBinding)
: QObject(parent), _enabled(enabled), _defaultActiveBinding(defaultActiveBinding), _remember(remember), _special(true), _module(nullptr)
{
_menuModel = new MenuModel(this, funcEntries);

setRequiresData(AnalysisEntry::requiresDataEntries(*funcEntries));
setModuleName(name);
setTitle(title);
_titleF = titleF;
_toolTipF = toolTipF;
setIconSource(tq(icon));
setToolTip(tq(toolTip));

bindYourself();
}
Expand Down Expand Up @@ -150,8 +149,6 @@ void RibbonButton::setReady(bool ready)
setEnabled(true);
}



RibbonButton::~RibbonButton()
{

Expand Down Expand Up @@ -291,6 +288,15 @@ void RibbonButton::setToolTip(QString toolTip)
emit toolTipChanged(_toolTip);
}

void RibbonButton::setToolTipF(std::function<QString()> toolTipF)
{
if ((!_toolTipF && !toolTipF) || (_toolTipF && toolTipF && _toolTipF() == toolTipF()))
return;

_toolTipF = toolTipF;
emit toolTipChanged(_toolTipF());
}

bool RibbonButton::separator() const
{
return _separator;
Expand Down
52 changes: 27 additions & 25 deletions Desktop/modules/ribbonbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class RibbonButton : public QObject

RibbonButton(QObject *parent);
RibbonButton(QObject *parent, Modules::DynamicModule * module);
RibbonButton(QObject *parent, std::string name, std::string title, std::string icon, bool requiresData, std::function<void()> justThisFunction, std::string toolTip = "", bool enabled = true, bool remember = false, bool defaultActiveBinding = true);
RibbonButton(QObject *parent, std::string name, std::string title, std::string icon, Modules::AnalysisEntries * funcEntries, std::string toolTip = "", bool enabled = true, bool remember = false, bool defaultActiveBinding = true);
RibbonButton(QObject *parent, std::string name, std::function<std::string()> titleF, std::string icon, bool requiresData, std::function<void()> justThisFunction, std::function<QString()> toolTipF = [](){return "";}, bool enabled = true, bool remember = false, bool defaultActiveBinding = true);
RibbonButton(QObject *parent, std::string name, std::function<std::string()> titleF, std::string icon, Modules::AnalysisEntries * funcEntries, std::function<QString()> toolTipF = [](){return "";}, bool enabled = true, bool remember = false, bool defaultActiveBinding = true);
~RibbonButton();


bool requiresData() const { return _requiresData; }
bool isCommon() const { return _isCommonModule; }
std::string title() const { return _title; }
QString titleQ() const { return QString::fromStdString(_title); }
std::string title() const { return _titleF ? _titleF() : _title; }
QString titleQ() const { return QString::fromStdString(title()); }
QString iconSource() const { return _iconSource; }
bool enabled() const { return _enabled; }
std::string name() const { return _name; }
Expand All @@ -75,39 +75,39 @@ class RibbonButton : public QObject
stringvec getAllEntries() const;
bool dataLoaded() const { return Modules::DynamicModules::dynMods() && Modules::DynamicModules::dynMods()->dataLoaded(); }
bool active() const { return _active; }
QString toolTip() const { return _toolTip; }
QString toolTip() const { return _toolTipF ? _toolTipF() : _toolTip; }
bool isBundled() const { return _module && _module->isBundled(); }
QString version() const { return !_module ? "?" : _module->versionQ(); }
bool ready() const { return _ready; }
bool error() const { return _error; }
bool remember() const { return _remember; }
bool isSpecial() const { return _special; }

static QString getJsonDescriptionFilename();
static QString getJsonDescriptionFilename();

bool separator() const;
void setSeparator(bool newSeparator);


public slots:
void setDynamicModule(Modules::DynamicModule * module);
void setRequiresData(bool requiresData);
void setIsCommon(bool isCommonModule);
void setTitle(std::string title);
void setTitleQ(QString title) { setTitle(title.toStdString()); }
void setIconSource(QString iconSource);
void setEnabled(bool enabled);
void setModuleName(std::string moduleName);
void setModuleNameQ(QString moduleName) { setModuleName(moduleName.toStdString()); }
void somePropertyChanged() { emit iChanged(this); }
void setToolTip(QString toolTip);
void setReady(bool ready);
void setError(bool error);
void setRemember(bool remember);
void setActive(bool active);


void runSpecial(QString func);;
void reloadDynamicModule(Modules::DynamicModule * dynMod);
void setDynamicModule( Modules::DynamicModule * module);
void setRequiresData( bool requiresData);
void setIsCommon( bool isCommonModule);
void setTitle( std::string title);
void setTitleQ( QString title) { setTitle(title.toStdString()); }
void setIconSource( QString iconSource);
void setEnabled( bool enabled);
void setModuleName( std::string moduleName);
void setModuleNameQ( QString moduleName) { setModuleName(moduleName.toStdString()); }
void somePropertyChanged() { emit iChanged(this); }
void setToolTip( QString toolTip);
void setToolTipF( std::function<QString ()> toolTipF);
void setReady( bool ready);
void setError( bool error);
void setRemember( bool remember);
void setActive( bool active);
void runSpecial( QString func);
void reloadDynamicModule( Modules::DynamicModule * dynMod);


signals:
Expand Down Expand Up @@ -152,6 +152,8 @@ public slots:
QString _iconSource,
_toolTip;
std::function<void()> _specialButtonFunc = nullptr;
std::function<std::string()> _titleF = nullptr;
std::function<QString()> _toolTipF = nullptr;
};


Expand Down
Loading
Loading