105 const auto itemKind = selectedProjectItem
108 const auto itemCategory = selectedProjectItem
112 std::vector<GraphicalComponent*> selectedNodes;
113 for (QGraphicsItem* item :
diagramScene->selectedItems()) {
114 if (
auto* component =
116 selectedNodes.push_back(component);
119 const bool hasProperties = !selectedNodes.empty()
128 auto* container =
new QWidget();
131 container->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
132 auto* layout =
new QFormLayout(container);
133 layout->setRowWrapPolicy(QFormLayout::WrapLongRows);
136 if (selectedNodes.empty()) {
137 if (!selectedProjectItem) {
138 layout->addRow(wrappingLabel(tr(
"Select a project, circuit, or one or more "
139 "components to view properties."),
152 wrappingLabel(tr(
"Select a %1 to view its properties.").arg(noun), container));
156 auto* nameEdit =
new QLineEdit(container);
157 auto* descriptionEdit =
new DescriptionEdit(container);
158 descriptionEdit->setMinimumHeight(90);
160 auto pushMetadataEdit = [
this](
const QString& label,
const std::string& oldValue,
161 const std::string& newValue,
163 if (oldValue == newValue)
171 auto schedulePropertyDockRefresh = [
this] {
172 QTimer::singleShot(0,
callbacks.context(), [
this] { refresh(); });
180 descriptionEdit->setPlainText(
182 descriptionEdit->document()->setModified(
false);
184 callbacks.connect(nameEdit, &QLineEdit::editingFinished,
185 [
this, nameEdit, pushMetadataEdit, schedulePropertyDockRefresh] {
190 const auto newValue = nameEdit->text().toStdString();
191 nameEdit->setModified(
false);
193 tr(
"Modify Project Name"), oldValue, newValue,
194 [
this, schedulePropertyDockRefresh](
const std::string& value) {
199 schedulePropertyDockRefresh();
202 descriptionEdit->commit =
callbacks.guard([
this, descriptionEdit, pushMetadataEdit,
203 schedulePropertyDockRefresh] {
208 const auto newValue = descriptionEdit->toPlainText().toStdString();
209 descriptionEdit->document()->setModified(
false);
210 pushMetadataEdit(tr(
"Modify Project Description"), oldValue, newValue,
211 [
this, schedulePropertyDockRefresh](
const std::string& value) {
215 schedulePropertyDockRefresh();
220 layout->addRow(wrappingLabel(tr(
"Name"), container), nameEdit);
221 layout->addRow(wrappingLabel(tr(
"Description"), container), descriptionEdit);
226 auto commonProps = selectedNodes.front()->getProperties();
228 std::erase_if(commonProps, [&](
const auto& pair) {
235 const auto& props = node->getProperties();
237 std::erase_if(commonProps, [&](
const auto& pair) {
238 const auto& [key, val] = pair;
239 auto it = props.find(key);
240 return it == props.end() || it->second.index() != val.index();
244 if (commonProps.empty()) {
245 layout->addRow(wrappingLabel(
246 tr(
"No common configurable properties among selection."), container));
252 auto applyProperty = [
this, selectedNodes](
const std::string& key,
255 auto command = std::make_unique<ModifyPropertyCommand>(key);
258 const auto oldValue = node->getProperty(key);
260 command->addPropertyChange(node, *oldValue, newVal);
263 if (command->isEmpty())
268 static_cast<void>(command.release());
269 if (key ==
"portOrientation") {
270 for (
const auto* node : selectedNodes) {
273 logic && logic->getComponent())
274 diagramScene->rememberIoPlacementOrientation(*logic->getComponent());
277 }
catch (
const std::exception& e) {
279 QTimer::singleShot(0,
callbacks.context(), [
this] { refresh(); });
284 for (
const auto& [key, initialValue] : commonProps) {
286 const bool isMixed = std::ranges::any_of(
291 auto createPropertyWidget = [&]<
typename T>(
const T& arg) {
292 if constexpr (std::is_same_v<T, bool>) {
293 auto* checkBox =
new QCheckBox(container);
296 checkBox->setTristate(
true);
297 checkBox->setCheckState(Qt::PartiallyChecked);
299 checkBox->setChecked(arg);
302 callbacks.connect(checkBox, &QCheckBox::checkStateChanged, [=](Qt::CheckState state) {
303 if (state == Qt::PartiallyChecked)
305 checkBox->setTristate(
false);
306 applyProperty(key, state == Qt::Checked);
309 layout->addRow(wrappingLabel(QString::fromStdString(key), container), checkBox);
310 }
else if constexpr (std::is_same_v<T, int>) {
312 constexpr int MIN_VAL = std::numeric_limits<int>::min();
313 constexpr int MAX_VAL = std::numeric_limits<int>::max();
315 spinBox->setRange(MIN_VAL, MAX_VAL);
318 spinBox->setMixed(
true, tr(
"Mixed values"));
320 spinBox->setValue(arg);
323 callbacks.connect(spinBox, &QSpinBox::valueChanged, [=](
int val) {
324 if (val == MIN_VAL && spinBox->isMixed())
326 spinBox->setMixed(
false);
327 applyProperty(key, val);
330 layout->addRow(wrappingLabel(QString::fromStdString(key), container), spinBox);
331 }
else if constexpr (std::is_same_v<T, std::string>) {
332 const auto stringOptions = selectedNodes.front()->getStringPropertyOptions(key);
334 auto* comboBox =
new QComboBox(container);
336 for (
const std::string& option : stringOptions->get()) {
337 comboBox->addItem(QString::fromStdString(option));
341 comboBox->setPlaceholderText(tr(
"Mixed values"));
342 comboBox->setCurrentIndex(-1);
344 comboBox->setCurrentText(QString::fromStdString(arg));
347 callbacks.connect(comboBox, &QComboBox::currentTextChanged,
348 [=](
const QString& text) {
351 applyProperty(key, text.toStdString());
354 layout->addRow(wrappingLabel(QString::fromStdString(key), container), comboBox);
358 if (std::ranges::all_of(selectedNodes, [&key](
const auto* node) {
361 auto* textEdit =
new DescriptionEdit(container);
362 textEdit->setMinimumHeight(90);
364 textEdit->setPlaceholderText(tr(
"Mixed values..."));
366 textEdit->setPlainText(QString::fromStdString(arg));
367 textEdit->document()->setModified(
false);
368 textEdit->commit =
callbacks.guard([textEdit, applyProperty, key] {
369 if (!textEdit->document()->isModified())
371 textEdit->document()->setModified(
false);
372 applyProperty(key, textEdit->toPlainText().toStdString());
374 layout->addRow(wrappingLabel(QString::fromStdString(key), container), textEdit);
378 auto* lineEdit =
new QLineEdit(container);
381 lineEdit->setPlaceholderText(tr(
"Mixed values..."));
383 lineEdit->setText(QString::fromStdString(arg));
386 callbacks.connect(lineEdit, &QLineEdit::editingFinished, [=]() {
387 if (!lineEdit->isModified())
390 applyProperty(key, lineEdit->text().toStdString());
391 lineEdit->setModified(
false);
394 layout->addRow(wrappingLabel(QString::fromStdString(key), container), lineEdit);
395 }
else if constexpr (std::is_same_v<T, BusValue>) {
396 auto* lineEdit =
new QLineEdit(container);
398 lineEdit->setPlaceholderText(tr(
"Mixed values..."));
400 lineEdit->setText(QString::fromStdString(
403 callbacks.connect(lineEdit, &QLineEdit::editingFinished, [=,
this]() {
404 if (!lineEdit->isModified())
409 lineEdit->setModified(
false);
410 }
catch (
const std::exception& error) {
416 layout->addRow(wrappingLabel(QString::fromStdString(key), container), lineEdit);
420 std::visit(createPropertyWidget, initialValue);