##// END OF EJS Templates
Handles QCustomPlot plottables for vectors (1)...
Handles QCustomPlot plottables for vectors (1) - Uses a map that associate a component index to a plottable. - Replaces the current structure by the map in VisualizationGraphHelper For example: - for a scalar, there is a QCPGraph at index 0 - for a vector, there is three QCPGraph at indexes 0, 1 and 2

File last commit:

r404:40749dfba67d
r581:098cadc4596c
Show More
MenuBuilder.h
61 lines | 1.7 KiB | text/x-c | CLexer
Alexandre Leroux
Moves MenuBuilder in a new class
r222 #ifndef SCIQLOP_MENUBUILDER_H
#define SCIQLOP_MENUBUILDER_H
#include <QLoggingCategory>
#include <QMenu>
#include <QStack>
Q_DECLARE_LOGGING_CATEGORY(LOG_MenuBuilder)
/// Helper assigned to build a hierarchical menu
class MenuBuilder {
public:
/**
* Ctor
* @param menu the parent menu
*/
explicit MenuBuilder(QMenu *menu);
/**
* Adds action to the current menu
* @param actionName the name of the action
* @param actionFunction the function that will be executed when the action is triggered
*/
template <typename ActionFun>
void addAction(const QString &actionName, ActionFun actionFunction);
/**
Alexandre Leroux
Disables 'plot' menu when variable data have not been loaded yet
r404 * Adds a new menu to the current menu and returns it
Alexandre Leroux
Moves MenuBuilder in a new class
r222 * @param name the name of the menu
Alexandre Leroux
Adds icon for 'Plot' menu
r322 * @param icon the icon of the menu (can be null)
Alexandre Leroux
Disables 'plot' menu when variable data have not been loaded yet
r404 * @returns the created menu, nullptr if it couldn't be created
Alexandre Leroux
Moves MenuBuilder in a new class
r222 */
Alexandre Leroux
Disables 'plot' menu when variable data have not been loaded yet
r404 QMenu *addMenu(const QString &name, const QIcon &icon = {});
Alexandre Leroux
Moves MenuBuilder in a new class
r222
/// Adds a separator to the current menu. The separator is added only if the menu already
/// contains entries
void addSeparator();
/// Closes the current menu
void closeMenu();
private:
/// @return the current menu (i.e. the top menu of the stack), nullptr if there is no menu
QMenu *currentMenu() const;
/// Stack of all menus currently opened
QStack<QMenu *> m_Menus{};
};
template <typename ActionFun>
void MenuBuilder::addAction(const QString &actionName, ActionFun actionFunction)
{
if (auto currMenu = currentMenu()) {
currMenu->addAction(actionName, actionFunction);
}
else {
qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the action");
}
}
#endif // SCIQLOP_MENUBUILDER_H