[solver] Add a warning message when a polynomial has no real root

This commit is contained in:
Émilie Feral
2019-01-09 11:01:32 +01:00
committed by Léa Saviot
parent 8cf6006a58
commit c3b335212c
2 changed files with 20 additions and 6 deletions

View File

@@ -16,8 +16,8 @@ using namespace Shared;
namespace Solver {
SolutionsController::ContentView::ContentView(SolutionsController * controller) :
m_warningMessageView0(KDFont::SmallFont, I18n::Message::OnlyFirstSolutionsDisplayed0, 0.5f, 0.5f, KDColorBlack, Palette::WallScreenDark),
m_warningMessageView1(KDFont::SmallFont, I18n::Message::OnlyFirstSolutionsDisplayed1, 0.5f, 0.5f, KDColorBlack, Palette::WallScreenDark),
m_warningMessageView0(KDFont::SmallFont, I18n::Message::Default, 0.5f, 0.5f, KDColorBlack, Palette::WallScreenDark),
m_warningMessageView1(KDFont::SmallFont, I18n::Message::Default, 0.5f, 0.5f, KDColorBlack, Palette::WallScreenDark),
m_selectableTableView(controller),
m_displayWarningMoreSolutions(false)
{
@@ -31,11 +31,15 @@ void SolutionsController::ContentView::drawRect(KDContext * ctx, KDRect rect) co
}
}
void SolutionsController::ContentView::setWarningMoreSolutions(bool warning) {
void SolutionsController::ContentView::setWarning(bool warning) {
m_displayWarningMoreSolutions = warning;
m_selectableTableView.setTopMargin(m_displayWarningMoreSolutions ? 0 : Metric::CommonTopMargin);
layoutSubviews();
markRectAsDirty(bounds());
}
void SolutionsController::ContentView::setWarningMessages(I18n::Message message0, I18n::Message message1) {
m_warningMessageView0.setMessage(message0);
m_warningMessageView1.setMessage(message1);
}
int SolutionsController::ContentView::numberOfSubviews() const {
@@ -100,7 +104,16 @@ View * SolutionsController::view() {
void SolutionsController::viewWillAppear() {
ViewController::viewWillAppear();
App * solverApp = static_cast<App *>(app());
m_contentView.setWarningMoreSolutions(m_equationStore->haveMoreApproximationSolutions(solverApp->localContext()));
bool requireWarning = false;
if (m_equationStore->type() == EquationStore::Type::Monovariable) {
m_contentView.setWarningMessages(I18n::Message::OnlyFirstSolutionsDisplayed0, I18n::Message::OnlyFirstSolutionsDisplayed1);
requireWarning = m_equationStore->haveMoreApproximationSolutions(solverApp->localContext());
} else if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && m_equationStore->numberOfSolutions() == 1) {
assert(Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Real);
m_contentView.setWarningMessages(I18n::Message::PolynomeHasNoRealSolution0, I18n::Message::PolynomeHasNoRealSolution1);
requireWarning = true;
}
m_contentView.setWarning(requireWarning);
m_contentView.selectableTableView()->reloadData();
if (selectedRow() < 0) {
selectCellAtLocation(0, 0);

View File

@@ -38,7 +38,8 @@ private:
public:
ContentView(SolutionsController * controller);
void drawRect(KDContext * ctx, KDRect rect) const override;
void setWarningMoreSolutions(bool warning);
void setWarning(bool warning);
void setWarningMessages(I18n::Message message0, I18n::Message message1);
SelectableTableView * selectableTableView() {
return &m_selectableTableView;
}