| 97 | } |
| 98 | |
| 99 | void WidgetSettingFloat::OnErrorValue() { |
| 100 | QPalette palette; |
| 101 | palette.setColor(QPalette::Base, QColor(255, 192, 192)); |
| 102 | this->field->setPalette(palette); |
| 103 | |
| 104 | Configurator& configurator = Configurator::Get(); |
| 105 | |
| 106 | if (!(configurator.Get(HIDE_MESSAGE_WIDGET_SETTING_FLOAT))) { |
| 107 | const std::string float_format = this->meta.GetFloatFormat(); |
| 108 | const std::string info = format("Do you want to reset to the setting default value? '%s'", float_format.c_str()); |
| 109 | const std::string range = this->meta.HasRange() |
| 110 | ? format("Enter a number in the range [%s, %s].", float_format.c_str(), float_format.c_str()) |
| 111 | : std::string("Enter a floating point number."); |
| 112 | |
| 113 | std::string text; |
| 114 | switch (this->ProcessInputValue()) { |
| 115 | default: |
| 116 | case SETTING_INPUT_NO_ERROR: { |
| 117 | assert(0); |
| 118 | break; |
| 119 | } |
| 120 | case SETTING_INPUT_ERROR_EMPTY: { |
| 121 | text = format(("'%s' value is empty. " + range).c_str(), this->meta.label.c_str(), this->meta.min_value, |
| 122 | this->meta.max_value); |
| 123 | break; |
| 124 | } |
| 125 | case SETTING_INPUT_ERROR_SYNTAX: { |
| 126 | text = format(("'%s' value has invalid characters. " + range).c_str(), this->meta.label.c_str(), |
| 127 | this->meta.min_value, this->meta.max_value); |
| 128 | break; |
| 129 | } |
| 130 | case SETTING_INPUT_ERROR_SEMENTICS: { |
| 131 | text = format(("'%s' value is out of range. " + range).c_str(), this->meta.label.c_str(), this->meta.min_value, |
| 132 | this->meta.max_value); |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | QMessageBox alert; |
| 138 | alert.setWindowTitle(format("Invalid '%s' setting value", meta.label.c_str()).c_str()); |
| 139 | alert.setText(text.c_str()); |
| 140 | alert.setInformativeText(format(info.c_str(), this->meta.default_value).c_str()); |
| 141 | alert.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
| 142 | alert.setDefaultButton(QMessageBox::Yes); |
| 143 | alert.setIcon(QMessageBox::Critical); |
| 144 | alert.setCheckBox(new QCheckBox("Do not show again.")); |
| 145 | if (alert.exec() == QMessageBox::Yes) { |
| 146 | const std::string field_value = format(this->meta.GetFloatFormat().c_str(), this->meta.default_value); |
| 147 | |
| 148 | this->data().value = this->meta.default_value; |
| 149 | this->field->setText(field_value.c_str()); |
| 150 | this->field->setPalette(default_palette); |
| 151 | this->Resize(); |
| 152 | } |
| 153 | if (alert.checkBox()->isChecked()) { |
| 154 | configurator.Set(HIDE_MESSAGE_WIDGET_SETTING_FLOAT); |
| 155 | } |
| 156 | } |
nothing calls this directly
no test coverage detected