mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:30:05 +00:00 
			
		
		
		
	Fixes to add_custom_layer_dialog suggested on GitHub
This commit is contained in:
		
							parent
							
								
									f5ab6f3ef7
								
							
						
					
					
						commit
						7d2635608d
					
				
					 4 changed files with 77 additions and 99 deletions
				
			
		|  | @ -44,6 +44,7 @@ public: | ||||||
|    void UpdateEditWidget(); |    void UpdateEditWidget(); | ||||||
|    void UpdateResetButton(); |    void UpdateResetButton(); | ||||||
|    void UpdateUnitLabel(); |    void UpdateUnitLabel(); | ||||||
|  |    void UpdateValidityDisplay(); | ||||||
| 
 | 
 | ||||||
|    SettingsInterface<T>* self_; |    SettingsInterface<T>* self_; | ||||||
| 
 | 
 | ||||||
|  | @ -173,23 +174,18 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|    { |    { | ||||||
|       if constexpr (std::is_same_v<T, std::string>) |       if constexpr (std::is_same_v<T, std::string>) | ||||||
|       { |       { | ||||||
|          QObject::connect( |          QObject::connect(hotkeyEdit, | ||||||
|             hotkeyEdit, |  | ||||||
|                           &ui::HotkeyEdit::KeySequenceChanged, |                           &ui::HotkeyEdit::KeySequenceChanged, | ||||||
|                           p->context_.get(), |                           p->context_.get(), | ||||||
|             [this, hotkeyEdit](const QKeySequence& sequence) |                           [this](const QKeySequence& sequence) | ||||||
|                           { |                           { | ||||||
|                const std::string value {sequence.toString().toStdString()}; |                              const std::string value { | ||||||
|  |                                 sequence.toString().toStdString()}; | ||||||
| 
 | 
 | ||||||
|                              // Attempt to stage the value
 |                              // Attempt to stage the value
 | ||||||
|                              p->stagedValid_ = p->variable_->StageValue(value); |                              p->stagedValid_ = p->variable_->StageValue(value); | ||||||
|                              p->UpdateResetButton(); |                              p->UpdateResetButton(); | ||||||
| 
 |                              p->UpdateValidityDisplay(); | ||||||
|                hotkeyEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : |  | ||||||
|                                                            kInvalidStyleSheet_); |  | ||||||
|                hotkeyEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? |  | ||||||
|                                          p->invalidTooltip_->c_str() : |  | ||||||
|                                          ""); |  | ||||||
|                           }); |                           }); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  | @ -199,11 +195,10 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|       { |       { | ||||||
|          // If the line is edited (not programatically changed), stage the new
 |          // If the line is edited (not programatically changed), stage the new
 | ||||||
|          // value
 |          // value
 | ||||||
|          QObject::connect( |          QObject::connect(lineEdit, | ||||||
|             lineEdit, |  | ||||||
|                           &QLineEdit::textEdited, |                           &QLineEdit::textEdited, | ||||||
|                           p->context_.get(), |                           p->context_.get(), | ||||||
|             [this, lineEdit](const QString& text) |                           [this](const QString& text) | ||||||
|                           { |                           { | ||||||
|                              const QString trimmedText = |                              const QString trimmedText = | ||||||
|                                 p->trimmingEnabled_ ? text.trimmed() : text; |                                 p->trimmingEnabled_ ? text.trimmed() : text; | ||||||
|  | @ -218,23 +213,17 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                              // Attempt to stage the value
 |                              // Attempt to stage the value
 | ||||||
|                              p->stagedValid_ = p->variable_->StageValue(value); |                              p->stagedValid_ = p->variable_->StageValue(value); | ||||||
|                              p->UpdateResetButton(); |                              p->UpdateResetButton(); | ||||||
| 
 |                              p->UpdateValidityDisplay(); | ||||||
|                lineEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : |  | ||||||
|                                                          kInvalidStyleSheet_); |  | ||||||
|                lineEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? |  | ||||||
|                                        p->invalidTooltip_->c_str() : |  | ||||||
|                                        ""); |  | ||||||
|                           }); |                           }); | ||||||
|       } |       } | ||||||
|       else if constexpr (std::is_same_v<T, double>) |       else if constexpr (std::is_same_v<T, double>) | ||||||
|       { |       { | ||||||
|          // If the line is edited (not programatically changed), stage the new
 |          // If the line is edited (not programatically changed), stage the new
 | ||||||
|          // value
 |          // value
 | ||||||
|          QObject::connect( |          QObject::connect(lineEdit, | ||||||
|             lineEdit, |  | ||||||
|                           &QLineEdit::textEdited, |                           &QLineEdit::textEdited, | ||||||
|                           p->context_.get(), |                           p->context_.get(), | ||||||
|             [this, lineEdit](const QString& text) |                           [this](const QString& text) | ||||||
|                           { |                           { | ||||||
|                              // Convert to a double
 |                              // Convert to a double
 | ||||||
|                              bool         ok    = false; |                              bool         ok    = false; | ||||||
|  | @ -242,7 +231,8 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                              if (ok) |                              if (ok) | ||||||
|                              { |                              { | ||||||
|                                 // Attempt to stage the value
 |                                 // Attempt to stage the value
 | ||||||
|                   p->stagedValid_ = p->variable_->StageValue(value); |                                 p->stagedValid_ = | ||||||
|  |                                    p->variable_->StageValue(value); | ||||||
|                                 p->UpdateResetButton(); |                                 p->UpdateResetButton(); | ||||||
|                              } |                              } | ||||||
|                              else |                              else | ||||||
|  | @ -251,11 +241,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                                 p->UpdateResetButton(); |                                 p->UpdateResetButton(); | ||||||
|                              } |                              } | ||||||
| 
 | 
 | ||||||
|                lineEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : |                              p->UpdateValidityDisplay(); | ||||||
|                                                          kInvalidStyleSheet_); |  | ||||||
|                lineEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? |  | ||||||
|                                        p->invalidTooltip_->c_str() : |  | ||||||
|                                        ""); |  | ||||||
|                           }); |                           }); | ||||||
|       } |       } | ||||||
|       else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) |       else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) | ||||||
|  | @ -266,7 +252,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|             lineEdit, |             lineEdit, | ||||||
|             &QLineEdit::textEdited, |             &QLineEdit::textEdited, | ||||||
|             p->context_.get(), |             p->context_.get(), | ||||||
|             [this, lineEdit](const QString& text) |             [this](const QString& text) | ||||||
|             { |             { | ||||||
|                // Map to value if required
 |                // Map to value if required
 | ||||||
|                T value {}; |                T value {}; | ||||||
|  | @ -300,12 +286,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                // Attempt to stage the value
 |                // Attempt to stage the value
 | ||||||
|                p->stagedValid_ = p->variable_->StageValue(value); |                p->stagedValid_ = p->variable_->StageValue(value); | ||||||
|                p->UpdateResetButton(); |                p->UpdateResetButton(); | ||||||
| 
 |                p->UpdateValidityDisplay(); | ||||||
|                lineEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : |  | ||||||
|                                                          kInvalidStyleSheet_); |  | ||||||
|                lineEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? |  | ||||||
|                                        p->invalidTooltip_->c_str() : |  | ||||||
|                                        ""); |  | ||||||
|             }); |             }); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  | @ -368,7 +349,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|             spinBox, |             spinBox, | ||||||
|             &QSpinBox::valueChanged, |             &QSpinBox::valueChanged, | ||||||
|             p->context_.get(), |             p->context_.get(), | ||||||
|             [this, spinBox](int i) |             [this](int i) | ||||||
|             { |             { | ||||||
|                const T                value  = p->variable_->GetValue(); |                const T                value  = p->variable_->GetValue(); | ||||||
|                const std::optional<T> staged = p->variable_->GetStaged(); |                const std::optional<T> staged = p->variable_->GetStaged(); | ||||||
|  | @ -390,11 +371,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                } |                } | ||||||
|                // Otherwise, don't process an unchanged value
 |                // Otherwise, don't process an unchanged value
 | ||||||
| 
 | 
 | ||||||
|                spinBox->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : |                p->UpdateValidityDisplay(); | ||||||
|                                                         kInvalidStyleSheet_); |  | ||||||
|                spinBox->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? |  | ||||||
|                                       p->invalidTooltip_->c_str() : |  | ||||||
|                                       ""); |  | ||||||
|             }); |             }); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  | @ -420,7 +397,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|             doubleSpinBox, |             doubleSpinBox, | ||||||
|             &QDoubleSpinBox::valueChanged, |             &QDoubleSpinBox::valueChanged, | ||||||
|             p->context_.get(), |             p->context_.get(), | ||||||
|             [this, doubleSpinBox](double d) |             [this](double d) | ||||||
|             { |             { | ||||||
|                if (p->unitEnabled_) |                if (p->unitEnabled_) | ||||||
|                { |                { | ||||||
|  | @ -447,12 +424,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | ||||||
|                } |                } | ||||||
|                // Otherwise, don't process an unchanged value
 |                // Otherwise, don't process an unchanged value
 | ||||||
| 
 | 
 | ||||||
|                doubleSpinBox->setStyleSheet( |                p->UpdateValidityDisplay(); | ||||||
|                   p->stagedValid_ ? kValidStyleSheet_ : kInvalidStyleSheet_); |  | ||||||
|                doubleSpinBox->setToolTip(p->invalidTooltip_ && |  | ||||||
|                                                !p->stagedValid_ ? |  | ||||||
|                                             p->invalidTooltip_->c_str() : |  | ||||||
|                                             ""); |  | ||||||
|             }); |             }); | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  | @ -662,6 +634,15 @@ void SettingsInterface<T>::Impl::UpdateUnitLabel() | ||||||
|    unitLabel_->setText(QString::fromStdString(unitAbbreviation_.value_or(""))); |    unitLabel_->setText(QString::fromStdString(unitAbbreviation_.value_or(""))); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | template<class T> | ||||||
|  | void SettingsInterface<T>::Impl::UpdateValidityDisplay() | ||||||
|  | { | ||||||
|  |    editWidget_->setStyleSheet(stagedValid_ ? kValidStyleSheet_ : | ||||||
|  |                                              kInvalidStyleSheet_); | ||||||
|  |    editWidget_->setToolTip( | ||||||
|  |       invalidTooltip_ && !stagedValid_ ? invalidTooltip_->c_str() : ""); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| template<class T> | template<class T> | ||||||
| void SettingsInterface<T>::Impl::UpdateResetButton() | void SettingsInterface<T>::Impl::UpdateResetButton() | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -17,15 +17,12 @@ class CustomLayerDialogImpl; | ||||||
| class CustomLayerDialog : public QDialog | class CustomLayerDialog : public QDialog | ||||||
| { | { | ||||||
|    Q_OBJECT |    Q_OBJECT | ||||||
|  |    Q_DISABLE_COPY_MOVE(CustomLayerDialog) | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    explicit CustomLayerDialog(const QMapLibre::Settings& settings, |    explicit CustomLayerDialog(const QMapLibre::Settings& settings, | ||||||
|                               QWidget*                   parent = nullptr); |                               QWidget*                   parent = nullptr); | ||||||
|    ~CustomLayerDialog() override; |    ~CustomLayerDialog() override; | ||||||
|    CustomLayerDialog(const CustomLayerDialog&)            = delete; |  | ||||||
|    CustomLayerDialog(CustomLayerDialog&&)                 = delete; |  | ||||||
|    CustomLayerDialog& operator=(const CustomLayerDialog&) = delete; |  | ||||||
|    CustomLayerDialog& operator=(CustomLayerDialog&&)      = delete; |  | ||||||
| 
 | 
 | ||||||
|    std::string selected_layer(); |    std::string selected_layer(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -109,7 +109,7 @@ class SettingsDialogImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit SettingsDialogImpl(SettingsDialog*      self, |    explicit SettingsDialogImpl(SettingsDialog*      self, | ||||||
|                                QMapLibre::Settings mapSettings) : |                                QMapLibre::Settings& mapSettings) : | ||||||
|        self_ {self}, |        self_ {self}, | ||||||
|        radarSiteDialog_ {new RadarSiteDialog(self)}, |        radarSiteDialog_ {new RadarSiteDialog(self)}, | ||||||
|        alertAudioRadarSiteDialog_ {new RadarSiteDialog(self)}, |        alertAudioRadarSiteDialog_ {new RadarSiteDialog(self)}, | ||||||
|  | @ -117,7 +117,7 @@ public: | ||||||
|        countyDialog_ {new CountyDialog(self)}, |        countyDialog_ {new CountyDialog(self)}, | ||||||
|        wfoDialog_ {new WFODialog(self)}, |        wfoDialog_ {new WFODialog(self)}, | ||||||
|        fontDialog_ {new QFontDialog(self)}, |        fontDialog_ {new QFontDialog(self)}, | ||||||
|        mapSettings_ {std::move(mapSettings)}, |        mapSettings_ {mapSettings}, | ||||||
|        fontCategoryModel_ {new QStandardItemModel(self)}, |        fontCategoryModel_ {new QStandardItemModel(self)}, | ||||||
|        settings_ {std::initializer_list<settings::SettingsInterfaceBase*> { |        settings_ {std::initializer_list<settings::SettingsInterfaceBase*> { | ||||||
|           &defaultRadarSite_, |           &defaultRadarSite_, | ||||||
|  | @ -223,7 +223,7 @@ public: | ||||||
|    WFODialog*        wfoDialog_; |    WFODialog*        wfoDialog_; | ||||||
|    QFontDialog*      fontDialog_; |    QFontDialog*      fontDialog_; | ||||||
| 
 | 
 | ||||||
|    QMapLibre::Settings mapSettings_; |    QMapLibre::Settings& mapSettings_; | ||||||
| 
 | 
 | ||||||
|    QStandardItemModel* fontCategoryModel_; |    QStandardItemModel* fontCategoryModel_; | ||||||
| 
 | 
 | ||||||
|  | @ -298,7 +298,7 @@ public: | ||||||
|    std::vector<settings::SettingsInterfaceBase*> settings_; |    std::vector<settings::SettingsInterfaceBase*> settings_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| SettingsDialog::SettingsDialog(const QMapLibre::Settings& mapSettings, | SettingsDialog::SettingsDialog(QMapLibre::Settings& mapSettings, | ||||||
|                                QWidget*             parent) : |                                QWidget*             parent) : | ||||||
|     QDialog(parent), |     QDialog(parent), | ||||||
|     p {std::make_unique<SettingsDialogImpl>(this, mapSettings)}, |     p {std::make_unique<SettingsDialogImpl>(this, mapSettings)}, | ||||||
|  |  | ||||||
|  | @ -25,7 +25,7 @@ private: | ||||||
|    Q_DISABLE_COPY(SettingsDialog) |    Q_DISABLE_COPY(SettingsDialog) | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    explicit SettingsDialog(const QMapLibre::Settings& mapSettings, |    explicit SettingsDialog(QMapLibre::Settings& mapSettings, | ||||||
|                            QWidget*             parent = nullptr); |                            QWidget*             parent = nullptr); | ||||||
|    ~SettingsDialog(); |    ~SettingsDialog(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak