4#include "ui_ParamsConfig.h"
5#include "moc_ParamsConfig.cpp"
14template <
typename DestinyType>
22template <
typename DestinyType>
36 : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
37 ui(std::make_unique<
Ui::ParamsConfig>()),
38 Core(Core), Object(nullptr), ResetRequired(false)
42 setWindowTitle(QString::fromStdString(Title));
52 auto SpinBox =
new QDoubleSpinBox(
this);
53 SpinBox->setDecimals(Precision);
54 SpinBox->setMinimum(MinValue);
55 SpinBox->setMaximum(MaxValue);
56 SpinBox->setSingleStep(Increment);
57 SpinBox->setValue(Value);
65 auto LineEdit =
new QLineEdit(
this);
66 LineEdit->setText(QString::fromStdString(Value));
74 const TextListType& TextList,
const bool AllowResetToDefault)
79 auto ComboBox =
new QComboBox(
this);
80 int SelectedIndex = 0;
82 for (
const auto& Entry : TextList)
85 SelectedIndex = ComboBox->count();
87 ComboBox->addItem(QString::fromStdString(Entry));
89 ComboBox->setCurrentIndex(SelectedIndex);
100 if (Value >= TextList.size())
101 throw Util::OutOfRangeException(
"A parameter's text list does not contain enough entries to select the specified initial value.");
102 if (DefaultValue >= TextList.size())
105 auto ComboBox =
new QComboBox(
this);
106 for (
const auto& Entry : TextList)
107 ComboBox->addItem(QString::fromStdString(Entry));
108 ComboBox->setCurrentIndex(Util::NumToT<int>(Value));
118 auto ComboBox =
new QComboBox(
this);
119 int SelectedIndex = 0;
126 for (
const auto& TextValuePair : ItemIDsWithLabels)
128 if (TextValuePair.second == Value)
129 SelectedIndex = ComboBox->count();
131 if (!IconResourcePath.empty())
132 ComboBox->addItem(QIcon(IconResourcePath.data()), QString::fromStdString(TextValuePair.first), QVariant(
static_cast<IndexType>(TextValuePair.second)));
134 ComboBox->addItem(QString::fromStdString(TextValuePair.first), QVariant(
static_cast<IndexType>(TextValuePair.second)));
136 ComboBox->setCurrentIndex(SelectedIndex);
146 auto ChoiceListDlg =
new ChoiceListDialog(
this, std::move(ItemIDsWithLabels), Info.Title, IsOptional, IconResourcePath, Values);
150 auto SetButton =
new QPushButton(
this);
151 SetButton->setProperty(
"ChoiceListDlg", QVariant::fromValue(ChoiceListDlg));
152 SetButton->setText(
"Select...");
153 if (!IconResourcePath.empty())
154 SetButton->setIcon(QIcon(IconResourcePath.data()));
155 connect(SetButton, &QPushButton::clicked, ChoiceListDlg, &QDialog::open);
169 layout()->setSizeConstraint(QLayout::SetFixedSize);
171 return exec() == DialogCode::Accepted;
176 auto Label =
new QLabel(QString::fromStdString(Info.Title),
this);
177 Label->setToolTip(QString::fromStdString(Info.Description));
178 ParamData.Widget->setToolTip(QString::fromStdString(Info.Description));
180 auto SubLayout = std::make_unique<QHBoxLayout>();
181 SubLayout->addWidget(ParamData.Widget);
183 ParamList.push_back(std::move(ParamData));
188 OpenButton->setToolTip(
"Browse...");
189 OpenButton->setMaximumWidth(24);
190 OpenButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
193 connect(OpenButton, SIGNAL(clicked()),
this, SLOT(
OnOpenParam()));
195 SubLayout->addWidget(OpenButton);
200 EditButton->setToolTip(
"Edit...");
201 EditButton->setMaximumWidth(24);
202 EditButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
205 connect(EditButton, SIGNAL(clicked()),
this, SLOT(
OnEditParam()));
207 SubLayout->addWidget(EditButton);
214 ResetButton->setToolTip(
"Reset to default value");
215 ResetButton->setMaximumWidth(24);
216 ResetButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
219 connect(ResetButton, SIGNAL(clicked()),
this, SLOT(
OnResetParam()));
221 SubLayout->addWidget(ResetButton);
224 ui->MainLayout->addRow(Label, SubLayout.release());
231 if (EditorDlg->isVisible())
234 auto Flags = EditorDlg->windowFlags();
235 EditorDlg->setParent(
nullptr);
236 EditorDlg->setWindowFlags(Flags);
238 EditorDlg->showNormal();
239 EditorDlg->setAttribute(Qt::WA_DeleteOnClose);
247 auto& ParamToOpen =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
253 if (!Filename.isEmpty())
254 static_cast<QLineEdit*
>(ParamToOpen.Widget)->setText(Filename);
260 auto& ParamToEdit =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
265 auto Filename =
static_cast<QLineEdit*
>(ParamToEdit.Widget)->text();
266 if (!Filename.isEmpty())
277 auto& ParamToReset =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
279 switch (ParamToReset.Type)
282 static_cast<QDoubleSpinBox*
>(ParamToReset.Widget)->setValue(
287 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentIndex(Util::NumToT<int>(ParamToReset.DefaultIndex));
292 static_cast<QLineEdit*
>(ParamToReset.Widget)->setText(
296 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentText(
300 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentIndex(Util::NumToT<int>(
322 switch (ParamEntry.Type)
326 static_cast<QDoubleSpinBox*
>(ParamEntry.Widget)->value());
340 static_cast<QLineEdit*
>(ParamEntry.Widget)->text().toStdString());
344 static_cast<QComboBox*
>(ParamEntry.Widget)->currentText().toStdString());
348 static_cast<QComboBox*
>(ParamEntry.Widget)->currentIndex());
351 Assign(std::any_cast<LinkParamRefWrapperType>(ParamEntry.Destiny).get(),
352 static_cast<QComboBox*
>(ParamEntry.Widget)->currentData().value<
IndexType>());
355 ChoiceListDlg =
static_cast<QPushButton*
>(ParamEntry.Widget)->property(
"ChoiceListDlg").value<
decltype(ChoiceListDlg)>();
360 QMessageBox::warning(
this,
"DynExp - Parameter empty",
361 QString(
"The parameter \"") + ChoiceListDlg->
GetParamName().data() +
"\" must not be empty. Please assign at least one item.");
364 Assign(std::any_cast<LinkListParamRefWrapperType>(ParamEntry.Destiny).get(), ChoiceListDlg->
GetSelection());
Defines DynExp's core module as an interface between the UI and DynExp objects.
Implementation of DynExp objects as the base for derived resources and implementation of the object p...
std::reference_wrapper< DynExp::ParamsBase::LinkListParamBase > LinkListParamRefWrapperType
Alias for a reference to a list parameter describing links to multiple DynExp::Object instances.
std::reference_wrapper< ParamWrapperType< DestinyType > > ParamRefWrapperType
Wraps ParamWrapperType into a std::reference_wrapper, thus defining a reference to a typed parameter.
std::reference_wrapper< DynExp::ParamsBase::LinkParamBase > LinkParamRefWrapperType
Alias for a reference to a parameter describing a link to another DynExp::Object instance.
Implements a configuration dialog which allows users to set values of parameters derived from DynExp:...
std::string_view GetParamName() const
bool IsOptional() const noexcept
const auto & GetSelection() const
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
std::filesystem::path ToAbsolutePath(const std::filesystem::path &Path) const
Transforms the path Path into an absolute path relative to ProjectParams::ProjectFilename.
Base class for all DynExp Objects like hardware adapters (DynExp::HardwareAdapterBase),...
ParamsConstTypeSyncPtrType GetParams(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Locks the mutex of the parameter class instance Params assigned to this Object instance and returns a...
Base class of parameters containing a single value.
uintmax_t EnumParamUnsignedIntegerType
Parameter type to convert unsigned eumeration parameters to.
intmax_t EnumParamSignedIntegerType
Parameter type to convert signed eumeration parameters to.
Util::TextListIndexType TextListIndexType
List index type of Util::TextListType.
std::vector< TextEditor * > TextEditorDialogs
Keeps a list of text editor dialogs so that their ownership can be removed when the ParamsConfigDialo...
qulonglong IndexType
ID type of objects/items managed by DynExp.
bool ResetRequired
Becomes true if an existing DynExp::Object is edited and needs to be reset to apply changes after cli...
std::unique_ptr< Ui::ParamsConfig > ui
Bundles Qt widgets of the ParamsConfigDialog instance's user interface.
void Assign(ParamT &Param, typename ParamT::UnderlyingType Value)
When the settings dialog is closed by accepting it, assign a single value from the user interface to ...
std::function< void(void)> FunctionsToCallIfAcceptedType
Signature of a function which is called when the ParamsConfigDialog is closed by the user by clicking...
double NumberType
Number type used for numeric parameters (DynExp::ParamsBase::Param)
void OnOpenParam()
Called when clicking the 'Browse' button for a DynExp::TextUsageType::Path or DynExp::TextUsageType::...
void OnResetParam()
Called when resetting a parameter to its default value.
DynExp::Object * Object
DynExp::Object whose parameters are edited. nullptr if a new DynExp::Object is created and synchroniz...
const DynExp::DynExpCore & Core
Reference to DynExp's core.
Util::TextRefType TextRefType
Reference-to-string type of text-type parameters (DynExp::ParamsBase::Param)
Util::TextListType TextListType
List type of text-type parameters.
virtual void reject() override
Called when the settings dialog is rejected clicking its 'Cancel' button.
void AddParam(ParamInfo &&Info, const std::any Destiny, const NumberType Value, const NumberType MinValue, const NumberType MaxValue, const NumberType Precision, const NumberType Increment)
Appends a parameter to the configuration dialog.
void InsertWidget(ParamInfo &&Info, Param &&ParamData)
Creates Qt widgets for editing a parameter and inserts them into the configuration dialog.
virtual void accept() override
Called when the settings dialog is accepted clicking its 'OK' button.
ParamsConfigDialog(QWidget *parent, const DynExp::DynExpCore &Core, std::string Title)
Constructs a ParamsConfigDialog instance.
std::vector< Param > ParamList
List of all parameters assigned to this ParamsConfigDialog instance.
std::vector< FunctionsToCallIfAcceptedType > FunctionsToCallIfAccepted
List of functions to be called when acceptig the dialog. Refer to ParamsConfigDialog::FunctionsToCall...
void OnEditParam()
Called when opening a TextEditor for a DynExp::TextUsageType::Code parameter.
void HandleTextEditorDialogsOnClose()
Called when the settings dialog is closed. Removes the parent widget of text editors listed in TextEd...
bool Display(DynExp::Object *Object=nullptr)
Displays the configuration dialog.
Util::TextType TextType
" String type of text-type parameters (DynExp::ParamsBase::Param)
Thrown when a list is expected to contain entries and when a query results in an empty answer or an e...
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
An operation cannot be performed currently since the related object is in an invalid state like an er...
Thrown when an argument passed to a function exceeds the valid range.
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
TextUsageType
Specifies the usage of a text-type parameter. Setting the right usage allows the ParamsConfigDialog t...
size_t ItemIDType
ID type of objects/items managed by DynExp.
QString PromptOpenFilePath(QWidget *Parent, const QString &Title, const QString &DefaultSuffix, const QString &NameFilter, const QString &InitialDirectory)
Opens a file dialog to ask the user to select a single existing file.
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Accumulates include statements to provide a precompiled header.
Bundles a parameter's title and description texts.
Collection of data defining a single parameter to be managed by a ParamsConfigDialog instance....