construct::ui::ValidationPresenter

The state, the header badge and the expansion of the Validation section of the definition editor.

Declared in src/libs/libconstruct/construct/ui/ValidationPresenter.hpp
Group construct

Detailed description

The definition editor gives the presenter each validation fact through apply(): a validation started, no validator ran, or a result with an error count and a warning count. apply() returns an Output, and the editor applies it to the section. The presenter has no widget, so the unit suite testDefinitionEditorLogic tests it with no display (construct-definition-editor §DUL-3a, §DUT-2d).

The five states and their badges:

State Badge text Badge role
Pending checking… SemanticPalette::Muted
Ok OK SemanticPalette::Success
Warnings 2 warnings SemanticPalette::Warning
Errors 1 error · 2 warnings SemanticPalette::Danger
Unavailable not checked SemanticPalette::Muted

Expansion follows transitions, not states (§DUL-3b):

  • A result in Errors or Warnings expands the section, when the last result had a different state.
  • A result in Ok collapses the section, when the last result had a different state.
  • A result with the state of the last result changes nothing.
  • Pending and Unavailable change nothing.

The presenter compares a result with the last result, not with the state on screen. Each validation shows Pending before its result, so a comparison with Pending makes every result a transition, and every Ok result then collapses the section. With the comparison to the last result, a section that the user opens while it is Ok stays open through the next validation. The presenter has no entry for a manual toggle and never reads the section, so the editor never fights the user.

The preview hook (§DUL-3e) is set for every result in Ok or Warnings. The editor then gives SDFPreviewWidget the text it validated. A result in the same state as the last result also sets it, because the text has changed between the two: the preview draws the last text that compiles, which is the behavior of the toolbar status label that the badge replaces. A result in Errors, Pending and Unavailable never set it, so the preview keeps the last good picture.

Both validation paths of the editor, the batch path and the synchronous path, convert their result with Input::fromValidationResult(), so one result type feeds one presenter (§DUL-3c).

The result type of both paths is construct::shader::ValidationResult, which has no page of its own.

See also SemanticPalette.

Member type documentation

Expansion enum

enum ValidationPresenter::Expansion

The change that the editor applies to the expansion of the section.

Constant Value Description
construct::ui::ValidationPresenter::Expansion::None 0 The editor does not change the expansion.
construct::ui::ValidationPresenter::Expansion::Expand 1 The editor expands the section.
construct::ui::ValidationPresenter::Expansion::Collapse 2 The editor collapses the section.

State enum

enum ValidationPresenter::State

The state of the Validation section.

Constant Value Description
construct::ui::ValidationPresenter::State::Pending 0 A validation started and has no result yet.
construct::ui::ValidationPresenter::State::Ok 1 The last result has no diagnostic.
construct::ui::ValidationPresenter::State::Warnings 2 The last result has warnings and no error.
construct::ui::ValidationPresenter::State::Errors 3 The last result has an error.
construct::ui::ValidationPresenter::State::Unavailable 4 No validator ran.

Member function documentation

apply

construct::ui::ValidationPresenter::Output ValidationPresenter::apply(const construct::ui::ValidationPresenter::Input &input)

Applies one validation fact and returns what the editor must do.

The state of the presenter becomes the state of input. The output carries the badge text, the badge role, the expansion change and the preview hook for that state, by the rules of the class description.

Returns the output for the section.

badgeRole

[static] SemanticPalette::Role ValidationPresenter::badgeRole(construct::ui::ValidationPresenter::State state)

Returns the SemanticPalette role of the badge for state.

The editor reads the colors of the role from SemanticPalette::current(), never from literals.

Returns Muted for Pending and Unavailable, Success for Ok, Warning for Warnings and Danger for Errors.

badgeText

[static] QString ValidationPresenter::badgeText(const construct::ui::ValidationPresenter::Input &input)

Returns the header badge text for input.

The texts are checking…, OK, 1 warning, 2 warnings, 1 error, 1 error · 2 warnings and not checked. The title of the section stays Validation.

state

construct::ui::ValidationPresenter::State ValidationPresenter::state() const

Returns the state on screen.

Returns the state of the last input, or Unavailable before the first input.

stateFor

[static] construct::ui::ValidationPresenter::State ValidationPresenter::stateFor(const construct::ui::ValidationPresenter::Input &input)

Returns the state that input puts the section in.

A result with an error is Errors. A result with warnings and no error is Warnings. A result with no diagnostic is Ok.