4 #include "moc_ParamsConfig.cpp"
13 template <
typename DestinyType>
21 template <
typename DestinyType>
35 : QDialog(parent, Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
36 Core(Core), Object(nullptr), ResetRequired(false)
40 setWindowTitle(QString::fromStdString(Title));
46 auto SpinBox =
new QDoubleSpinBox(
this);
47 SpinBox->setDecimals(Precision);
48 SpinBox->setMinimum(MinValue);
49 SpinBox->setMaximum(MaxValue);
50 SpinBox->setSingleStep(Increment);
51 SpinBox->setValue(Value);
59 auto LineEdit =
new QLineEdit(
this);
60 LineEdit->setText(QString::fromStdString(Value));
68 const TextListType& TextList,
const bool AllowResetToDefault)
73 auto ComboBox =
new QComboBox(
this);
74 int SelectedIndex = 0;
76 for (
const auto& Entry : TextList)
79 SelectedIndex = ComboBox->count();
81 ComboBox->addItem(QString::fromStdString(Entry));
83 ComboBox->setCurrentIndex(SelectedIndex);
94 if (Value >= TextList.size())
95 throw Util::OutOfRangeException(
"A parameter's text list does not contain enough entries to select the specified initial value.");
96 if (DefaultValue >= TextList.size())
99 auto ComboBox =
new QComboBox(
this);
100 for (
const auto& Entry : TextList)
101 ComboBox->addItem(QString::fromStdString(Entry));
102 ComboBox->setCurrentIndex(Util::NumToT<int>(Value));
112 auto ComboBox =
new QComboBox(
this);
113 int SelectedIndex = 0;
120 for (
const auto& TextValuePair : ItemIDsWithLabels)
122 if (TextValuePair.second == Value)
123 SelectedIndex = ComboBox->count();
125 if (!IconResourcePath.empty())
126 ComboBox->addItem(QIcon(IconResourcePath.data()), QString::fromStdString(TextValuePair.first), QVariant(
static_cast<IndexType>(TextValuePair.second)));
128 ComboBox->addItem(QString::fromStdString(TextValuePair.first), QVariant(
static_cast<IndexType>(TextValuePair.second)));
130 ComboBox->setCurrentIndex(SelectedIndex);
140 auto ChoiceListDlg =
new ChoiceListDialog(
this, std::move(ItemIDsWithLabels),
Info.Title, IsOptional, IconResourcePath, Values);
144 auto SetButton =
new QPushButton(
this);
145 SetButton->setProperty(
"ChoiceListDlg", QVariant::fromValue(ChoiceListDlg));
146 SetButton->setText(
"Select...");
147 if (!IconResourcePath.empty())
148 SetButton->setIcon(QIcon(IconResourcePath.data()));
149 connect(SetButton, &QPushButton::clicked, ChoiceListDlg, &QDialog::open);
163 layout()->setSizeConstraint(QLayout::SetFixedSize);
165 return exec() == DialogCode::Accepted;
170 auto Label =
new QLabel(QString::fromStdString(
Info.Title),
this);
171 Label->setToolTip(QString::fromStdString(
Info.Description));
172 ParamData.Widget->setToolTip(QString::fromStdString(
Info.Description));
174 auto SubLayout = std::make_unique<QHBoxLayout>();
175 SubLayout->addWidget(ParamData.Widget);
177 ParamList.push_back(std::move(ParamData));
182 OpenButton->setToolTip(
"Browse...");
183 OpenButton->setMaximumWidth(24);
184 OpenButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
187 connect(OpenButton, SIGNAL(clicked()),
this, SLOT(
OnOpenParam()));
189 SubLayout->addWidget(OpenButton);
194 EditButton->setToolTip(
"Edit...");
195 EditButton->setMaximumWidth(24);
196 EditButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
199 connect(EditButton, SIGNAL(clicked()),
this, SLOT(
OnEditParam()));
201 SubLayout->addWidget(EditButton);
208 ResetButton->setToolTip(
"Reset to default value");
209 ResetButton->setMaximumWidth(24);
210 ResetButton->setProperty(
"ParamID", QVariant::fromValue(
ParamList.size() - 1));
213 connect(ResetButton, SIGNAL(clicked()),
this, SLOT(
OnResetParam()));
215 SubLayout->addWidget(ResetButton);
218 ui.MainLayout->addRow(Label, SubLayout.release());
225 if (EditorDlg->isVisible())
228 auto Flags = EditorDlg->windowFlags();
229 EditorDlg->setParent(
nullptr);
230 EditorDlg->setWindowFlags(Flags);
232 EditorDlg->showNormal();
233 EditorDlg->setAttribute(Qt::WA_DeleteOnClose);
241 auto& ParamToOpen =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
247 if (!Filename.isEmpty())
248 static_cast<QLineEdit*
>(ParamToOpen.Widget)->setText(Filename);
254 auto& ParamToEdit =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
259 auto Filename =
static_cast<QLineEdit*
>(ParamToEdit.Widget)->text();
260 if (!Filename.isEmpty())
271 auto& ParamToReset =
ParamList.at(qobject_cast<QPushButton*>(sender())->property(
"ParamID").value<size_t>());
273 switch (ParamToReset.Type)
276 static_cast<QDoubleSpinBox*
>(ParamToReset.Widget)->setValue(
281 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentIndex(Util::NumToT<int>(ParamToReset.DefaultIndex));
286 static_cast<QLineEdit*
>(ParamToReset.Widget)->setText(
290 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentText(
294 static_cast<QComboBox*
>(ParamToReset.Widget)->setCurrentIndex(Util::NumToT<int>(
316 switch (ParamEntry.Type)
320 static_cast<QDoubleSpinBox*
>(ParamEntry.Widget)->value());
334 static_cast<QLineEdit*
>(ParamEntry.Widget)->text().toStdString());
338 static_cast<QComboBox*
>(ParamEntry.Widget)->currentText().toStdString());
342 static_cast<QComboBox*
>(ParamEntry.Widget)->currentIndex());
345 Assign(std::any_cast<LinkParamRefWrapperType>(ParamEntry.Destiny).get(),
346 static_cast<QComboBox*
>(ParamEntry.Widget)->currentData().value<
IndexType>());
349 ChoiceListDlg =
static_cast<QPushButton*
>(ParamEntry.Widget)->property(
"ChoiceListDlg").value<decltype(ChoiceListDlg)>();
354 QMessageBox::warning(
this,
"DynExp - Parameter empty",
355 QString(
"The parameter \"") + ChoiceListDlg->
GetParamName().data() +
"\" must not be empty. Please assign at least one item.");
358 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...
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....