mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:10:05 +00:00 
			
		
		
		
	Fix up custom map inputs, making it easier for others to use
This commit is contained in:
		
							parent
							
								
									c9ead60dd4
								
							
						
					
					
						commit
						fee00b737a
					
				
					 11 changed files with 425 additions and 65 deletions
				
			
		|  | @ -258,6 +258,7 @@ set(HDR_UI source/scwx/qt/ui/about_dialog.hpp | |||
|            source/scwx/qt/ui/api_key_edit_widget.hpp | ||||
|            source/scwx/qt/ui/collapsible_group.hpp | ||||
|            source/scwx/qt/ui/county_dialog.hpp | ||||
|            source/scwx/qt/ui/custom_layer_dialog.hpp | ||||
|            source/scwx/qt/ui/download_dialog.hpp | ||||
|            source/scwx/qt/ui/edit_line_dialog.hpp | ||||
|            source/scwx/qt/ui/edit_marker_dialog.hpp | ||||
|  | @ -290,6 +291,7 @@ set(SRC_UI source/scwx/qt/ui/about_dialog.cpp | |||
|            source/scwx/qt/ui/api_key_edit_widget.cpp | ||||
|            source/scwx/qt/ui/collapsible_group.cpp | ||||
|            source/scwx/qt/ui/county_dialog.cpp | ||||
|            source/scwx/qt/ui/custom_layer_dialog.cpp | ||||
|            source/scwx/qt/ui/download_dialog.cpp | ||||
|            source/scwx/qt/ui/edit_line_dialog.cpp | ||||
|            source/scwx/qt/ui/edit_marker_dialog.cpp | ||||
|  | @ -321,6 +323,7 @@ set(UI_UI  source/scwx/qt/ui/about_dialog.ui | |||
|            source/scwx/qt/ui/animation_dock_widget.ui | ||||
|            source/scwx/qt/ui/collapsible_group.ui | ||||
|            source/scwx/qt/ui/county_dialog.ui | ||||
|            source/scwx/qt/ui/custom_layer_dialog.ui | ||||
|            source/scwx/qt/ui/edit_line_dialog.ui | ||||
|            source/scwx/qt/ui/edit_marker_dialog.ui | ||||
|            source/scwx/qt/ui/gps_info_dialog.ui | ||||
|  |  | |||
|  | @ -316,7 +316,7 @@ MainWindow::MainWindow(QWidget* parent) : | |||
|    p->layerDialog_ = new ui::LayerDialog(this); | ||||
| 
 | ||||
|    // Settings Dialog
 | ||||
|    p->settingsDialog_ = new ui::SettingsDialog(this); | ||||
|    p->settingsDialog_ = new ui::SettingsDialog(p->settings_, this); | ||||
| 
 | ||||
|    // Map Settings
 | ||||
|    p->mapSettingsGroup_ = new ui::CollapsibleGroup(tr("Map Settings"), this); | ||||
|  |  | |||
|  | @ -107,6 +107,10 @@ public: | |||
|          SCWX_SETTINGS_ENUM_VALIDATOR(scwx::util::ClockFormat, | ||||
|                                       scwx::util::ClockFormatIterator(), | ||||
|                                       scwx::util::GetClockFormatName)); | ||||
| 
 | ||||
|       customStyleUrl_.SetValidator( | ||||
|          [](const std::string& value) | ||||
|          { return value.find("key=") == std::string::npos; }); | ||||
|       customStyleDrawLayer_.SetValidator([](const std::string& value) | ||||
|                                          { return !value.empty(); }); | ||||
|       defaultAlertAction_.SetValidator( | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ | |||
| #include <QLineEdit> | ||||
| #include <QSpinBox> | ||||
| #include <QWidget> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace scwx::qt::settings | ||||
|  | @ -19,6 +20,9 @@ namespace scwx::qt::settings | |||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::settings::settings_interface"; | ||||
| 
 | ||||
| static const QString kValidStyleSheet_   = ""; | ||||
| static const QString kInvalidStyleSheet_ = "border: 2px solid red;"; | ||||
| 
 | ||||
| template<class T> | ||||
| class SettingsInterface<T>::Impl | ||||
| { | ||||
|  | @ -59,6 +63,8 @@ public: | |||
|    bool                       unitEnabled_ {false}; | ||||
| 
 | ||||
|    bool trimmingEnabled_ {false}; | ||||
| 
 | ||||
|    std::optional<std::string> invalidTooltip_; | ||||
| }; | ||||
| 
 | ||||
| template<class T> | ||||
|  | @ -167,20 +173,24 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|    { | ||||
|       if constexpr (std::is_same_v<T, std::string>) | ||||
|       { | ||||
|          QObject::connect(hotkeyEdit, | ||||
|                           &ui::HotkeyEdit::KeySequenceChanged, | ||||
|                           p->context_.get(), | ||||
|                           [this](const QKeySequence& sequence) | ||||
|                           { | ||||
|                              std::string value { | ||||
|                                 sequence.toString().toStdString()}; | ||||
|          QObject::connect( | ||||
|             hotkeyEdit, | ||||
|             &ui::HotkeyEdit::KeySequenceChanged, | ||||
|             p->context_.get(), | ||||
|             [this, hotkeyEdit](const QKeySequence& sequence) | ||||
|             { | ||||
|                const std::string value {sequence.toString().toStdString()}; | ||||
| 
 | ||||
|                              // Attempt to stage the value
 | ||||
|                              p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                              p->UpdateResetButton(); | ||||
|                // Attempt to stage the value
 | ||||
|                p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                p->UpdateResetButton(); | ||||
| 
 | ||||
|                              // TODO: Display invalid status
 | ||||
|                           }); | ||||
|                hotkeyEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : | ||||
|                                                            kInvalidStyleSheet_); | ||||
|                hotkeyEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? | ||||
|                                          p->invalidTooltip_->c_str() : | ||||
|                                          ""); | ||||
|             }); | ||||
|       } | ||||
|    } | ||||
|    else if (QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(widget)) | ||||
|  | @ -189,53 +199,64 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|       { | ||||
|          // If the line is edited (not programatically changed), stage the new
 | ||||
|          // value
 | ||||
|          QObject::connect(lineEdit, | ||||
|                           &QLineEdit::textEdited, | ||||
|                           p->context_.get(), | ||||
|                           [this](const QString& text) | ||||
|                           { | ||||
|                              QString trimmedText = | ||||
|                                 p->trimmingEnabled_ ? text.trimmed() : text; | ||||
|          QObject::connect( | ||||
|             lineEdit, | ||||
|             &QLineEdit::textEdited, | ||||
|             p->context_.get(), | ||||
|             [this, lineEdit](const QString& text) | ||||
|             { | ||||
|                const QString trimmedText = | ||||
|                   p->trimmingEnabled_ ? text.trimmed() : text; | ||||
| 
 | ||||
|                              // Map to value if required
 | ||||
|                              std::string value {trimmedText.toStdString()}; | ||||
|                              if (p->mapToValue_ != nullptr) | ||||
|                              { | ||||
|                                 value = p->mapToValue_(value); | ||||
|                              } | ||||
|                // Map to value if required
 | ||||
|                std::string value {trimmedText.toStdString()}; | ||||
|                if (p->mapToValue_ != nullptr) | ||||
|                { | ||||
|                   value = p->mapToValue_(value); | ||||
|                } | ||||
| 
 | ||||
|                              // Attempt to stage the value
 | ||||
|                              p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                              p->UpdateResetButton(); | ||||
|                // Attempt to stage the value
 | ||||
|                p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                p->UpdateResetButton(); | ||||
| 
 | ||||
|                              // TODO: Display invalid status
 | ||||
|                           }); | ||||
|                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>) | ||||
|       { | ||||
|          // If the line is edited (not programatically changed), stage the new
 | ||||
|          // value
 | ||||
|          QObject::connect(lineEdit, | ||||
|                           &QLineEdit::textEdited, | ||||
|                           p->context_.get(), | ||||
|                           [this](const QString& text) | ||||
|                           { | ||||
|                              // Convert to a double
 | ||||
|                              bool   ok; | ||||
|                              double value = text.toDouble(&ok); | ||||
|                              if (ok) | ||||
|                              { | ||||
|                                 // Attempt to stage the value
 | ||||
|                                 p->stagedValid_ = | ||||
|                                    p->variable_->StageValue(value); | ||||
|                                 p->UpdateResetButton(); | ||||
|                              } | ||||
|                              else | ||||
|                              { | ||||
|                                 p->stagedValid_ = false; | ||||
|                                 p->UpdateResetButton(); | ||||
|                              } | ||||
|                           }); | ||||
|          QObject::connect( | ||||
|             lineEdit, | ||||
|             &QLineEdit::textEdited, | ||||
|             p->context_.get(), | ||||
|             [this, lineEdit](const QString& text) | ||||
|             { | ||||
|                // Convert to a double
 | ||||
|                bool         ok    = false; | ||||
|                const double value = text.toDouble(&ok); | ||||
|                if (ok) | ||||
|                { | ||||
|                   // Attempt to stage the value
 | ||||
|                   p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                   p->UpdateResetButton(); | ||||
|                } | ||||
|                else | ||||
|                { | ||||
|                   p->stagedValid_ = false; | ||||
|                   p->UpdateResetButton(); | ||||
|                } | ||||
| 
 | ||||
|                lineEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : | ||||
|                                                          kInvalidStyleSheet_); | ||||
|                lineEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? | ||||
|                                        p->invalidTooltip_->c_str() : | ||||
|                                        ""); | ||||
|             }); | ||||
|       } | ||||
|       else if constexpr (std::is_same_v<T, std::vector<std::int64_t>>) | ||||
|       { | ||||
|  | @ -245,7 +266,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|             lineEdit, | ||||
|             &QLineEdit::textEdited, | ||||
|             p->context_.get(), | ||||
|             [this](const QString& text) | ||||
|             [this, lineEdit](const QString& text) | ||||
|             { | ||||
|                // Map to value if required
 | ||||
|                T value {}; | ||||
|  | @ -280,7 +301,11 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|                p->stagedValid_ = p->variable_->StageValue(value); | ||||
|                p->UpdateResetButton(); | ||||
| 
 | ||||
|                // TODO: Display invalid status
 | ||||
|                lineEdit->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : | ||||
|                                                          kInvalidStyleSheet_); | ||||
|                lineEdit->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? | ||||
|                                        p->invalidTooltip_->c_str() : | ||||
|                                        ""); | ||||
|             }); | ||||
|       } | ||||
|    } | ||||
|  | @ -343,7 +368,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|             spinBox, | ||||
|             &QSpinBox::valueChanged, | ||||
|             p->context_.get(), | ||||
|             [this](int i) | ||||
|             [this, spinBox](int i) | ||||
|             { | ||||
|                const T                value  = p->variable_->GetValue(); | ||||
|                const std::optional<T> staged = p->variable_->GetStaged(); | ||||
|  | @ -364,6 +389,12 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|                   p->UpdateResetButton(); | ||||
|                } | ||||
|                // Otherwise, don't process an unchanged value
 | ||||
| 
 | ||||
|                spinBox->setStyleSheet(p->stagedValid_ ? kValidStyleSheet_ : | ||||
|                                                         kInvalidStyleSheet_); | ||||
|                spinBox->setToolTip(p->invalidTooltip_ && !p->stagedValid_ ? | ||||
|                                       p->invalidTooltip_->c_str() : | ||||
|                                       ""); | ||||
|             }); | ||||
|       } | ||||
|    } | ||||
|  | @ -389,7 +420,7 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|             doubleSpinBox, | ||||
|             &QDoubleSpinBox::valueChanged, | ||||
|             p->context_.get(), | ||||
|             [this](double d) | ||||
|             [this, doubleSpinBox](double d) | ||||
|             { | ||||
|                if (p->unitEnabled_) | ||||
|                { | ||||
|  | @ -415,6 +446,13 @@ void SettingsInterface<T>::SetEditWidget(QWidget* widget) | |||
|                   p->UpdateResetButton(); | ||||
|                } | ||||
|                // Otherwise, don't process an unchanged value
 | ||||
| 
 | ||||
|                doubleSpinBox->setStyleSheet( | ||||
|                   p->stagedValid_ ? kValidStyleSheet_ : kInvalidStyleSheet_); | ||||
|                doubleSpinBox->setToolTip(p->invalidTooltip_ && | ||||
|                                                !p->stagedValid_ ? | ||||
|                                             p->invalidTooltip_->c_str() : | ||||
|                                             ""); | ||||
|             }); | ||||
|       } | ||||
|    } | ||||
|  | @ -500,6 +538,12 @@ void SettingsInterface<T>::EnableTrimming(bool trimmingEnabled) | |||
|    p->trimmingEnabled_ = trimmingEnabled; | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| void SettingsInterface<T>::SetInvalidTooltip(std::optional<std::string> tooltip) | ||||
| { | ||||
|    p->invalidTooltip_ = std::move(tooltip); | ||||
| } | ||||
| 
 | ||||
| template<class T> | ||||
| template<class U> | ||||
| void SettingsInterface<T>::Impl::SetWidgetText(U* widget, const T& currentValue) | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <optional> | ||||
| #include <scwx/qt/settings/settings_interface_base.hpp> | ||||
| 
 | ||||
| #include <functional> | ||||
|  | @ -130,6 +131,13 @@ public: | |||
|     */ | ||||
|    void EnableTrimming(bool trimmingEnabled = true); | ||||
| 
 | ||||
|    /**
 | ||||
|     * Set a tooltip to be displayed when an invalid input is given. | ||||
|     * | ||||
|     * @param tooltip the tooltip to be displayed | ||||
|     */ | ||||
|    void SetInvalidTooltip(std::optional<std::string> tooltip); | ||||
| 
 | ||||
| private: | ||||
|    class Impl; | ||||
|    std::unique_ptr<Impl> p; | ||||
|  |  | |||
							
								
								
									
										124
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,124 @@ | |||
| #include "custom_layer_dialog.hpp" | ||||
| #include "ui_custom_layer_dialog.h" | ||||
| 
 | ||||
| #include <re2/re2.h> | ||||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <utility> | ||||
| 
 | ||||
| namespace scwx::qt::ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::ui::custom_layer_dialog"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class CustomLayerDialogImpl | ||||
| { | ||||
| public: | ||||
|    explicit CustomLayerDialogImpl(CustomLayerDialog*  self, | ||||
|                                   QMapLibre::Settings settings) : | ||||
|        self_(self), settings_(std::move(settings)) | ||||
|    { | ||||
|    } | ||||
| 
 | ||||
|    ~CustomLayerDialogImpl()                                       = default; | ||||
|    CustomLayerDialogImpl(const CustomLayerDialogImpl&)            = delete; | ||||
|    CustomLayerDialogImpl(CustomLayerDialogImpl&&)                 = delete; | ||||
|    CustomLayerDialogImpl& operator=(const CustomLayerDialogImpl&) = delete; | ||||
|    CustomLayerDialogImpl& operator=(CustomLayerDialogImpl&&)      = delete; | ||||
| 
 | ||||
|    void handle_mapChanged(QMapLibre::Map::MapChange change); | ||||
| 
 | ||||
|    CustomLayerDialog* self_; | ||||
| 
 | ||||
|    QMapLibre::Settings             settings_; | ||||
|    std::shared_ptr<QMapLibre::Map> map_; | ||||
| }; | ||||
| 
 | ||||
| // TODO Duplicated form map_widget, Should probably be moved.
 | ||||
| static bool match_layer(const std::string& pattern, const std::string& layer) | ||||
| { | ||||
|    // Perform case-insensitive matching
 | ||||
|    const RE2 re {"(?i)" + pattern}; | ||||
|    if (re.ok()) | ||||
|    { | ||||
|       return RE2::FullMatch(layer, re); | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       // Fall back to basic comparison if RE
 | ||||
|       // doesn't compile
 | ||||
|       return layer == pattern; | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| void CustomLayerDialogImpl::handle_mapChanged(QMapLibre::Map::MapChange change) | ||||
| { | ||||
|    if (change == QMapLibre::Map::MapChange::MapChangeDidFinishLoadingStyle) | ||||
|    { | ||||
|       auto& generalSettings = settings::GeneralSettings::Instance(); | ||||
|       const std::string& customStyleDrawLayer = | ||||
|          generalSettings.custom_style_draw_layer().GetValue(); | ||||
| 
 | ||||
|       const QStringList layerIds = map_->layerIds(); | ||||
|       self_->ui->layerListWidget->clear(); | ||||
|       self_->ui->layerListWidget->addItems(layerIds); | ||||
| 
 | ||||
|       for (int i = 0; i < self_->ui->layerListWidget->count(); i++) | ||||
|       { | ||||
|          auto* item = self_->ui->layerListWidget->item(i); | ||||
| 
 | ||||
|          if (match_layer(customStyleDrawLayer, item->text().toStdString())) | ||||
|          { | ||||
|             self_->ui->layerListWidget->setCurrentItem(item); | ||||
|          } | ||||
|       } | ||||
|    } | ||||
| } | ||||
| 
 | ||||
| CustomLayerDialog::CustomLayerDialog(const QMapLibre::Settings& settings, | ||||
|                                      QWidget*                   parent) : | ||||
|     QDialog(parent), | ||||
|     p {std::make_unique<CustomLayerDialogImpl>(this, settings)}, | ||||
|     ui(new Ui::CustomLayerDialog) | ||||
| { | ||||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    auto&       generalSettings = settings::GeneralSettings::Instance(); | ||||
|    const auto& customStyleUrl  = generalSettings.custom_style_url().GetValue(); | ||||
|    const auto  mapProvider = | ||||
|       map::GetMapProvider(generalSettings.map_provider().GetValue()); | ||||
| 
 | ||||
|    // TODO render the map with a layer to show what they are selecting
 | ||||
|    p->map_ = std::make_shared<QMapLibre::Map>( | ||||
|       nullptr, p->settings_, QSize(1, 1), devicePixelRatioF()); | ||||
| 
 | ||||
|    QString qUrl = QString::fromStdString(customStyleUrl); | ||||
| 
 | ||||
|    if (mapProvider == map::MapProvider::MapTiler) | ||||
|    { | ||||
|       qUrl.append("?key="); | ||||
|       qUrl.append(map::GetMapProviderApiKey(mapProvider)); | ||||
|    } | ||||
| 
 | ||||
|    p->map_->setStyleUrl(qUrl); | ||||
| 
 | ||||
|    QObject::connect(p->map_.get(), | ||||
|                     &QMapLibre::Map::mapChanged, | ||||
|                     this, | ||||
|                     [this](QMapLibre::Map::MapChange change) | ||||
|                     { p->handle_mapChanged(change); }); | ||||
| } | ||||
| 
 | ||||
| CustomLayerDialog::~CustomLayerDialog() | ||||
| { | ||||
|    delete ui; | ||||
| } | ||||
| 
 | ||||
| std::string CustomLayerDialog::selected_layer() | ||||
| { | ||||
|    return ui->layerListWidget->currentItem()->text().toStdString(); | ||||
| } | ||||
| 
 | ||||
| } // namespace scwx::qt::ui
 | ||||
							
								
								
									
										38
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <qmaplibre.hpp> | ||||
| #include <QDialog> | ||||
| #include <string> | ||||
| 
 | ||||
| namespace Ui | ||||
| { | ||||
| class CustomLayerDialog; | ||||
| } | ||||
| 
 | ||||
| namespace scwx::qt::ui | ||||
| { | ||||
| 
 | ||||
| class CustomLayerDialogImpl; | ||||
| 
 | ||||
| class CustomLayerDialog : public QDialog | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit CustomLayerDialog(const QMapLibre::Settings& settings, | ||||
|                               QWidget*                   parent = nullptr); | ||||
|    ~CustomLayerDialog() override; | ||||
|    CustomLayerDialog(const CustomLayerDialog&)            = delete; | ||||
|    CustomLayerDialog(CustomLayerDialog&&)                 = delete; | ||||
|    CustomLayerDialog& operator=(const CustomLayerDialog&) = delete; | ||||
|    CustomLayerDialog& operator=(CustomLayerDialog&&)      = delete; | ||||
| 
 | ||||
|    std::string selected_layer(); | ||||
| 
 | ||||
| private: | ||||
|    friend class CustomLayerDialogImpl; | ||||
|    std::unique_ptr<CustomLayerDialogImpl> p; | ||||
|    Ui::CustomLayerDialog*                 ui; | ||||
| }; | ||||
| 
 | ||||
| } // namespace scwx::qt::ui
 | ||||
							
								
								
									
										96
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.ui
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								scwx-qt/source/scwx/qt/ui/custom_layer_dialog.ui
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,96 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ui version="4.0"> | ||||
|  <class>CustomLayerDialog</class> | ||||
|  <widget class="QDialog" name="CustomLayerDialog"> | ||||
|   <property name="geometry"> | ||||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>308</width> | ||||
|     <height>300</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="sizePolicy"> | ||||
|    <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | ||||
|     <horstretch>0</horstretch> | ||||
|     <verstretch>0</verstretch> | ||||
|    </sizepolicy> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>Custom Map Style Draw Layer</string> | ||||
|   </property> | ||||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <item> | ||||
|     <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|      <item> | ||||
|       <widget class="QListWidget" name="layerListWidget"> | ||||
|        <property name="sizePolicy"> | ||||
|         <sizepolicy hsizetype="Preferred" vsizetype="Expanding"> | ||||
|          <horstretch>0</horstretch> | ||||
|          <verstretch>0</verstretch> | ||||
|         </sizepolicy> | ||||
|        </property> | ||||
|        <property name="editTriggers"> | ||||
|         <set>QAbstractItemView::EditTrigger::NoEditTriggers</set> | ||||
|        </property> | ||||
|        <property name="alternatingRowColors"> | ||||
|         <bool>true</bool> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|      <property name="sizePolicy"> | ||||
|       <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> | ||||
|        <horstretch>0</horstretch> | ||||
|        <verstretch>0</verstretch> | ||||
|       </sizepolicy> | ||||
|      </property> | ||||
|      <property name="orientation"> | ||||
|       <enum>Qt::Orientation::Horizontal</enum> | ||||
|      </property> | ||||
|      <property name="standardButtons"> | ||||
|       <set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|   </layout> | ||||
|  </widget> | ||||
|  <resources/> | ||||
|  <connections> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>accepted()</signal> | ||||
|    <receiver>CustomLayerDialog</receiver> | ||||
|    <slot>accept()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>248</x> | ||||
|      <y>254</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>157</x> | ||||
|      <y>274</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>rejected()</signal> | ||||
|    <receiver>CustomLayerDialog</receiver> | ||||
|    <slot>reject()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>316</x> | ||||
|      <y>260</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>286</x> | ||||
|      <y>274</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|  </connections> | ||||
| </ui> | ||||
|  | @ -24,6 +24,7 @@ | |||
| #include <scwx/qt/types/time_types.hpp> | ||||
| #include <scwx/qt/types/unit_types.hpp> | ||||
| #include <scwx/qt/ui/county_dialog.hpp> | ||||
| #include <scwx/qt/ui/custom_layer_dialog.hpp> | ||||
| #include <scwx/qt/ui/radar_site_dialog.hpp> | ||||
| #include <scwx/qt/ui/serial_port_dialog.hpp> | ||||
| #include <scwx/qt/ui/settings/alert_palette_settings_widget.hpp> | ||||
|  | @ -45,6 +46,7 @@ | |||
| #include <QPushButton> | ||||
| #include <QStandardItemModel> | ||||
| #include <QToolButton> | ||||
| #include <utility> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -106,7 +108,8 @@ static const std::unordered_map<std::string, ColorTableConversions> | |||
| class SettingsDialogImpl | ||||
| { | ||||
| public: | ||||
|    explicit SettingsDialogImpl(SettingsDialog* self) : | ||||
|    explicit SettingsDialogImpl(SettingsDialog*     self, | ||||
|                                QMapLibre::Settings mapSettings) : | ||||
|        self_ {self}, | ||||
|        radarSiteDialog_ {new RadarSiteDialog(self)}, | ||||
|        alertAudioRadarSiteDialog_ {new RadarSiteDialog(self)}, | ||||
|  | @ -114,6 +117,7 @@ public: | |||
|        countyDialog_ {new CountyDialog(self)}, | ||||
|        wfoDialog_ {new WFODialog(self)}, | ||||
|        fontDialog_ {new QFontDialog(self)}, | ||||
|        mapSettings_ {std::move(mapSettings)}, | ||||
|        fontCategoryModel_ {new QStandardItemModel(self)}, | ||||
|        settings_ {std::initializer_list<settings::SettingsInterfaceBase*> { | ||||
|           &defaultRadarSite_, | ||||
|  | @ -219,6 +223,8 @@ public: | |||
|    WFODialog*        wfoDialog_; | ||||
|    QFontDialog*      fontDialog_; | ||||
| 
 | ||||
|    QMapLibre::Settings mapSettings_; | ||||
| 
 | ||||
|    QStandardItemModel* fontCategoryModel_; | ||||
| 
 | ||||
|    types::FontCategory selectedFontCategory_ {types::FontCategory::Unknown}; | ||||
|  | @ -292,9 +298,10 @@ public: | |||
|    std::vector<settings::SettingsInterfaceBase*> settings_; | ||||
| }; | ||||
| 
 | ||||
| SettingsDialog::SettingsDialog(QWidget* parent) : | ||||
| SettingsDialog::SettingsDialog(const QMapLibre::Settings& mapSettings, | ||||
|                                QWidget*                   parent) : | ||||
|     QDialog(parent), | ||||
|     p {std::make_unique<SettingsDialogImpl>(this)}, | ||||
|     p {std::make_unique<SettingsDialogImpl>(this, mapSettings)}, | ||||
|     ui(new Ui::SettingsDialog) | ||||
| { | ||||
|    ui->setupUi(this); | ||||
|  | @ -685,12 +692,39 @@ void SettingsDialogImpl::SetupGeneralTab() | |||
|    customStyleUrl_.SetSettingsVariable(generalSettings.custom_style_url()); | ||||
|    customStyleUrl_.SetEditWidget(self_->ui->customMapUrlLineEdit); | ||||
|    customStyleUrl_.SetResetButton(self_->ui->resetCustomMapUrlButton); | ||||
|    customStyleUrl_.SetInvalidTooltip( | ||||
|       "Remove anything following \"?key=\" in the URL"); | ||||
|    customStyleUrl_.EnableTrimming(); | ||||
| 
 | ||||
|    customStyleDrawLayer_.SetSettingsVariable( | ||||
|       generalSettings.custom_style_draw_layer()); | ||||
|    customStyleDrawLayer_.SetEditWidget(self_->ui->customMapLayerLineEdit); | ||||
|    customStyleDrawLayer_.SetResetButton(self_->ui->resetCustomMapLayerButton); | ||||
|    QObject::connect( | ||||
|       self_->ui->customMapLayerToolButton, | ||||
|       &QAbstractButton::clicked, | ||||
|       self_, | ||||
|       [this]() | ||||
|       { | ||||
|          // WA_DeleteOnClose manages memory
 | ||||
|          // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
 | ||||
|          auto* customLayerDialog = new ui::CustomLayerDialog(mapSettings_); | ||||
|          customLayerDialog->setAttribute(Qt::WA_DeleteOnClose); | ||||
|          QObject::connect( | ||||
|             customLayerDialog, | ||||
|             &QDialog::accepted, | ||||
|             self_, | ||||
|             [this, customLayerDialog]() | ||||
|             { | ||||
|                auto newLayer = customLayerDialog->selected_layer(); | ||||
|                self_->ui->customMapLayerLineEdit->setText(newLayer.c_str()); | ||||
|                // setText does not emit the textEdited signal
 | ||||
|                Q_EMIT | ||||
|                self_->ui->customMapLayerLineEdit->textEdited(newLayer.c_str()); | ||||
|             }); | ||||
| 
 | ||||
|          customLayerDialog->open(); | ||||
|       }); | ||||
| 
 | ||||
|    defaultAlertAction_.SetSettingsVariable( | ||||
|       generalSettings.default_alert_action()); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QDialog> | ||||
| #include <qmaplibre.hpp> | ||||
| 
 | ||||
| namespace Ui | ||||
| { | ||||
|  | @ -24,7 +25,8 @@ private: | |||
|    Q_DISABLE_COPY(SettingsDialog) | ||||
| 
 | ||||
| public: | ||||
|    explicit SettingsDialog(QWidget* parent = nullptr); | ||||
|    explicit SettingsDialog(const QMapLibre::Settings& mapSettings, | ||||
|                            QWidget*                   parent = nullptr); | ||||
|    ~SettingsDialog(); | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -122,7 +122,7 @@ | |||
|           </sizepolicy> | ||||
|          </property> | ||||
|          <property name="currentIndex"> | ||||
|           <number>3</number> | ||||
|           <number>0</number> | ||||
|          </property> | ||||
|          <widget class="QWidget" name="general"> | ||||
|           <layout class="QVBoxLayout" name="verticalLayout_2"> | ||||
|  | @ -135,9 +135,9 @@ | |||
|               <property name="geometry"> | ||||
|                <rect> | ||||
|                 <x>0</x> | ||||
|                 <y>-303</y> | ||||
|                 <y>-260</y> | ||||
|                 <width>511</width> | ||||
|                 <height>733</height> | ||||
|                 <height>812</height> | ||||
|                </rect> | ||||
|               </property> | ||||
|               <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|  | @ -608,6 +608,13 @@ | |||
|                     </property> | ||||
|                    </widget> | ||||
|                   </item> | ||||
|                   <item row="15" column="3"> | ||||
|                    <widget class="QToolButton" name="customMapLayerToolButton"> | ||||
|                     <property name="text"> | ||||
|                      <string>...</string> | ||||
|                     </property> | ||||
|                    </widget> | ||||
|                   </item> | ||||
|                  </layout> | ||||
|                 </widget> | ||||
|                </item> | ||||
|  | @ -714,8 +721,8 @@ | |||
|                    <rect> | ||||
|                     <x>0</x> | ||||
|                     <y>0</y> | ||||
|                     <width>98</width> | ||||
|                     <height>28</height> | ||||
|                     <width>80</width> | ||||
|                     <height>18</height> | ||||
|                    </rect> | ||||
|                   </property> | ||||
|                   <layout class="QGridLayout" name="gridLayout_3"> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 AdenKoperczak
						AdenKoperczak