99 lines
3.5 KiB
C++
Executable File
99 lines
3.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Helper Classes to manage requirements for end-users to ui elements
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2016-08-19
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QWidget>
|
|
#include <QVector>
|
|
#include <functional>
|
|
|
|
|
|
class QLabel;
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
/**
|
|
* @brief The UiRequirement class describes a single UiRequirement. An UiRequirement is used to check that (valid) data is entered
|
|
* by a user into an editable Widget. After an UiRequirement is created, it automatically changes the description Label of the
|
|
* editable Widget by adding "[*]" to visualize that this Widget must be filled. If an UiRequirement is not met after executing the
|
|
* checkRequirement-Method, the Label is colored red to visualize an error to the user.
|
|
*
|
|
*/
|
|
class LTSWIDGETS_EXPORT UiRequirement // TODO: optional requirements => simply non-marked labels with advanced requirement checks (MessageDialog with message that e.g. "val of [widget-description] is too small")
|
|
{
|
|
public:
|
|
explicit UiRequirement() = default;
|
|
|
|
/**
|
|
* @brief UiRequirement
|
|
* @param descriptionLabel the Label, usually left of the editable Widget in a Form Layout, which describes the editable Widget to be checked
|
|
* @param requirementCheck the routine (c++11) to check if requirements are met for the editable Widget to be checked - return values: true when requirement(s) are met, false when not
|
|
*/
|
|
UiRequirement(QLabel *descriptionLabel, const std::function<bool()> &requirementCheck, const QString &userWarningMessage = QString());
|
|
|
|
void reset();
|
|
|
|
/**
|
|
* @brief checkRequirement executes the requirementCheck function. If the description Label of the editable Widget is not visible,
|
|
* the requirement check is ignored (as, logically, the Widget is then optional). If the requirement is not met, the
|
|
* description Label of the editable Widget is colored red.
|
|
* @return true if requirement is met (or description Label of Widget is hidden (optional)), false if not met
|
|
*/
|
|
bool checkRequirement();
|
|
|
|
bool isValid() const { return m_descriptionLabel != nullptr; }
|
|
|
|
void retranslate();
|
|
|
|
private:
|
|
void setTexts();
|
|
|
|
QLabel *m_descriptionLabel;
|
|
std::function<bool()> m_requirementCheck;
|
|
QString m_originalText;
|
|
QString m_originalTooltip;
|
|
bool m_lastResult;
|
|
QString m_userWarningMessage;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief The UiRequirementList class provides a list which contains UiRequirements, that can all be checked by one method call.
|
|
*/
|
|
class LTSWIDGETS_EXPORT UiRequirementList
|
|
{
|
|
public:
|
|
UiRequirementList() = default;
|
|
|
|
/**
|
|
* @brief checkRequirements checks every requirement in this list. If one or more requirements are not met, this method returns false.
|
|
* @param messageOnThisParent set this pointer to a QWidget to let the UiRequirementList generate a LtsMessageDialog which states that there are non-met requirements for the user, set to nullptr to not show a message
|
|
* @return true if all requirements are met, false if one or more requirements have NOT met
|
|
*/
|
|
bool checkRequirements(QWidget *messageOnThisParent = nullptr);
|
|
|
|
/**
|
|
* @brief addRequirement adds an UiRequirement to this list.
|
|
* @param uiRequirement the UiRequirement to be copied & added.
|
|
*/
|
|
void addRequirement(const UiRequirement &uiRequirement);
|
|
|
|
void clear();
|
|
|
|
void retranslate(); // TODO: remove after every UiReq is inside retranslate()-method
|
|
|
|
private:
|
|
QVector<UiRequirement> m_requirementList; // TODo: to ptr as QVector does a graceful copy of the UiReq class, causing the original class to be destroyed
|
|
};
|
|
} // namespace LtsWidgets
|