154 lines
3.3 KiB
C++
Executable File
154 lines
3.3 KiB
C++
Executable File
|
|
|
|
|
|
#include "ui_requirement.h"
|
|
|
|
#include <LtsWidgets/lts_message_dialog.h>
|
|
|
|
#include <QApplication>
|
|
#include <QLabel>
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
UiRequirement::UiRequirement(QLabel *descriptionLabel, const std::function<bool()> &requirementCheck, const QString &userWarningMessage)
|
|
: m_descriptionLabel(descriptionLabel)
|
|
, m_requirementCheck(requirementCheck)
|
|
, m_lastResult(true)
|
|
, m_userWarningMessage(userWarningMessage)
|
|
{
|
|
retranslate();
|
|
}
|
|
|
|
|
|
void UiRequirement::reset()
|
|
{
|
|
if (!isValid())
|
|
return;
|
|
m_descriptionLabel->setText(m_originalText);
|
|
m_descriptionLabel->setToolTip(m_originalTooltip);
|
|
}
|
|
|
|
|
|
void UiRequirement::setTexts()
|
|
{
|
|
if (!isValid())
|
|
return;
|
|
if (!m_lastResult)
|
|
{
|
|
m_descriptionLabel->setText(QStringLiteral("<span style=\"color:#aa0000;\">\u2022 %1</span>").arg(m_originalText));
|
|
|
|
if (!m_userWarningMessage.isEmpty())
|
|
{
|
|
m_descriptionLabel->setCursor(Qt::WhatsThisCursor);
|
|
m_descriptionLabel->setToolTip(m_userWarningMessage);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
|
return;
|
|
|
|
m_descriptionLabel->setText(QStringLiteral("\u2022 %1").arg(m_originalText));
|
|
m_descriptionLabel->setCursor(Qt::ArrowCursor);
|
|
m_descriptionLabel->setToolTip(m_originalTooltip);
|
|
}
|
|
}
|
|
|
|
|
|
void UiRequirement::retranslate()
|
|
{
|
|
if (!isValid())
|
|
return;
|
|
|
|
if (m_originalText.startsWith(QStringLiteral("\u2022 ")))
|
|
return;
|
|
|
|
auto x = m_descriptionLabel->text();
|
|
if (x.startsWith(QStringLiteral("\u2022 ")))
|
|
return;
|
|
|
|
m_originalText = x;
|
|
|
|
m_originalTooltip = m_descriptionLabel->toolTip();
|
|
setTexts();
|
|
}
|
|
|
|
|
|
bool UiRequirement::checkRequirement()
|
|
{
|
|
if (!isValid())
|
|
return m_lastResult;
|
|
|
|
m_lastResult = m_requirementCheck();
|
|
|
|
if (!m_descriptionLabel->isVisible() && !m_descriptionLabel->property("checkMe").toBool())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
setTexts();
|
|
|
|
return m_lastResult;
|
|
}
|
|
|
|
|
|
bool UiRequirementList::checkRequirements(QWidget *messageOnThisParent)
|
|
{
|
|
bool result = true;
|
|
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
|
{
|
|
UiRequirement &r = (*i);
|
|
|
|
|
|
if (!r.isValid())
|
|
continue;
|
|
|
|
if (!r.checkRequirement())
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
if (!result && messageOnThisParent)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(messageOnThisParent,
|
|
QApplication::translate("LtsWidgets::LtsDialog",
|
|
"There are elements that have invalid or no value.<br>"
|
|
"Please change values in the elements which are marked with red text."),
|
|
QApplication::translate("LtsWidgets::LtsDialog", "Operation not complete"));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
void UiRequirementList::addRequirement(const UiRequirement &uiRequirement)
|
|
{
|
|
m_requirementList.append(uiRequirement);
|
|
}
|
|
|
|
|
|
void UiRequirementList::clear()
|
|
{
|
|
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
|
{
|
|
UiRequirement &uir = *i;
|
|
uir.reset();
|
|
}
|
|
|
|
m_requirementList.clear();
|
|
}
|
|
|
|
|
|
void UiRequirementList::retranslate()
|
|
{
|
|
for (auto i = m_requirementList.begin(); i != m_requirementList.end(); ++i)
|
|
{
|
|
UiRequirement &r = (*i);
|
|
|
|
r.retranslate();
|
|
}
|
|
}
|
|
}
|