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

Analysis constraint error should not be closeable #5572

Merged
merged 2 commits into from
Jun 18, 2024
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
3 changes: 3 additions & 0 deletions Desktop/analysis/analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ void Analysis::run()

void Analysis::refresh()
{
if (form() && form()->hasError())
return;

TempFiles::deleteAll(int(_id));
run();

Expand Down
11 changes: 3 additions & 8 deletions QMLComponents/analysisform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ void AnalysisForm::refreshAnalysis()
_analysis->refresh();
}

void AnalysisForm::runAnalysis()
{
_analysis->run();
refreshTableViewModels();
}

QString AnalysisForm::generateWrapper() const
{
return _rSyntax->generateWrapper();
Expand Down Expand Up @@ -398,7 +392,7 @@ void AnalysisForm::addFormWarning(const QString & warning)

//This should be moved to JASPControl maybe?
//Maybe even to full QML? Why don't we just use a loader...
void AnalysisForm::addControlError(JASPControl* control, QString message, bool temporary, bool warning)
void AnalysisForm::addControlError(JASPControl* control, QString message, bool temporary, bool warning, bool closeable)
{
if (!control)
{
Expand Down Expand Up @@ -450,6 +444,7 @@ void AnalysisForm::addControlError(JASPControl* control, QString message, bool t

controlErrorMessageItem->setProperty("control", QVariant::fromValue(control));
controlErrorMessageItem->setProperty("warning", warning);
controlErrorMessageItem->setProperty("closeable", closeable);
controlErrorMessageItem->setParentItem(container);
QMetaObject::invokeMethod(controlErrorMessageItem, "showMessage", Qt::QueuedConnection, Q_ARG(QVariant, message), Q_ARG(QVariant, temporary));
}
Expand All @@ -465,7 +460,7 @@ bool AnalysisForm::hasError()
// Controls handling inside a form must indeed be done in anther way!

for (QQuickItem* item : _controlErrorMessageCache)
if (item->property("control").value<JASPControl*>() != nullptr)
if (item->property("control").value<JASPControl*>() != nullptr && !item->property("warning").toBool())
return true;

return false;
Expand Down
3 changes: 1 addition & 2 deletions QMLComponents/analysisform.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,10 @@ public slots:
Q_INVOKABLE void addFormError(const QString& message);
Q_INVOKABLE void addFormWarning(const QString& message);
Q_INVOKABLE void refreshAnalysis();
Q_INVOKABLE void runAnalysis();
Q_INVOKABLE bool initialized() const { return _initialized; }
Q_INVOKABLE QString generateWrapper() const;

void addControlError(JASPControl* control, QString message, bool temporary = false, bool warning = false);
void addControlError(JASPControl* control, QString message, bool temporary = false, bool warning = false, bool closeable = true);
void clearControlError(JASPControl* control);
void cleanUpForm();
bool hasError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Rectangle
property var control
property bool tmp : false
property bool warning : false
property bool closeable : true
property var form
property var container : parent
property int containerWidth : container ? (container === form ? form.availableWidth : container.width) : 0
Expand Down Expand Up @@ -159,6 +160,7 @@ Rectangle

CrossButton
{
visible: closeable
onCrossClicked:
{
controlErrorMessage.opacity = 0
Expand Down
6 changes: 6 additions & 0 deletions QMLComponents/controls/jaspcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ void JASPControl::addControlErrorTemporary(QString message)
_form->addControlError(this, message, true);
}

void JASPControl::addControlErrorPermanent(QString message)
{
if (_form && message.size())
_form->addControlError(this, message, false, false, false);
}

void JASPControl::addControlWarning(QString message)
{
if (_form && message.size())
Expand Down
1 change: 1 addition & 0 deletions QMLComponents/controls/jaspcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public slots:

void addControlError( QString message);
void addControlErrorTemporary( QString message);
void addControlErrorPermanent( QString message);
void addControlWarning( QString message);
void addControlWarningTemporary( QString message);
void clearControlError();
Expand Down
8 changes: 4 additions & 4 deletions QMLComponents/controls/variableslistbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,22 @@ void VariablesListBase::termsChangedHandler()
int nbNumValues = model()->requestInfo(VariableInfo::TotalNumericValues, term.asQString()).toInt();
if (_minLevels >= 0 && nbLevels < _minLevels)
{
addControlError(tr("Minimum number of levels is %1. Variable %2 has only %3 levels").arg(_minLevels).arg(term.asQString()).arg(nbLevels));
addControlErrorPermanent(tr("Minimum number of levels is %1. Variable %2 has only %3 levels").arg(_minLevels).arg(term.asQString()).arg(nbLevels));
hasError = true;
}
else if (_maxLevels >= 0 && nbLevels > _maxLevels)
{
addControlError(tr("Maximum number of levels is %1. Variable %2 has %3 levels").arg(_maxLevels).arg(term.asQString()).arg(nbLevels));
addControlErrorPermanent(tr("Maximum number of levels is %1. Variable %2 has %3 levels").arg(_maxLevels).arg(term.asQString()).arg(nbLevels));
hasError = true;
}
else if (_minNumericLevels >= 0 && nbNumValues < _minNumericLevels)
{
addControlError(tr("Minumum number of numeric values is %1. Variable %2 has only %3 different numeric values").arg(_minNumericLevels).arg(term.asQString()).arg(nbNumValues));
addControlErrorPermanent(tr("Minumum number of numeric values is %1. Variable %2 has only %3 different numeric values").arg(_minNumericLevels).arg(term.asQString()).arg(nbNumValues));
hasError = true;
}
else if (_maxNumericLevels >= 0 && nbNumValues > _maxNumericLevels)
{
addControlError(tr("Maximum number of numeric values is %1. Variable %2 has %3 different numeric values").arg(_maxNumericLevels).arg(term.asQString()).arg(nbNumValues));
addControlErrorPermanent(tr("Maximum number of numeric values is %1. Variable %2 has %3 different numeric values").arg(_maxNumericLevels).arg(term.asQString()).arg(nbNumValues));
hasError = true;
}

Expand Down
Loading