Refactor context menu and link button logic

This commit is contained in:
Kellermorph
2026-03-31 17:52:26 +02:00
committed by GitHub
parent ecee2209e6
commit 3795ddb1f5

View File

@@ -342,7 +342,7 @@ void MasterPropertiesWidget::headerCustomContextMenuRequested(const QPoint &pos)
{ {
m_context_menu->clear(); m_context_menu->clear();
m_context_menu->addAction(m_save_header_state); m_context_menu->addAction(m_save_header_state);
m_context_menu->popup(ui->m_free_tree_widget->header()->mapToGlobal(pos)); m_context_menu->popup(ui->m_free_tree_widget->header()->mapToGlobal(pos));
} }
/** /**
@@ -352,33 +352,33 @@ m_context_menu->popup(ui->m_free_tree_widget->header()->mapToGlobal(pos));
*/ */
void MasterPropertiesWidget::on_link_button_clicked() void MasterPropertiesWidget::on_link_button_clicked()
{ {
// Get the maximum number of allowed slaves from the element's information // Get the maximum number of allowed slaves from the element's information
QVariant max_slaves_variant = m_element->kindInformations().value("max_slaves"); QVariant max_slaves_variant = m_element->kindInformations().value("max_slaves");
if (max_slaves_variant.isValid() && !max_slaves_variant.toString().isEmpty()) { if (max_slaves_variant.isValid() && !max_slaves_variant.toString().isEmpty()) {
int max_slaves = max_slaves_variant.toInt(); int max_slaves = max_slaves_variant.toInt();
int current_slaves = ui->m_link_tree_widget->topLevelItemCount(); int current_slaves = ui->m_link_tree_widget->topLevelItemCount();
// If a limit is set and reached // If a limit is set and reached
if (max_slaves != -1 && current_slaves >= max_slaves) { if (max_slaves != -1 && current_slaves >= max_slaves) {
// Show a message box with the actual window as parent to ensure it's on top // Show a message box with the actual window as parent to ensure it's on top
QMessageBox::warning(this->window(), QMessageBox::warning(this->window(),
tr("Maximum Slaves Reached"), tr("Maximum Slaves Reached"),
tr("This master element cannot accept any new slaves because it is full (Limit: %1).").arg(max_slaves)); tr("This master element cannot accept any new slaves because it is full (Limit: %1).").arg(max_slaves));
return; return;
} }
} }
// Move current item from free_list to linked_list // Move current item from free_list to linked_list
QTreeWidgetItem *qtwi = ui->m_free_tree_widget->currentItem(); QTreeWidgetItem *qtwi = ui->m_free_tree_widget->currentItem();
if (qtwi) if (qtwi)
{ {
ui->m_free_tree_widget->takeTopLevelItem( ui->m_free_tree_widget->takeTopLevelItem(
ui->m_free_tree_widget->indexOfTopLevelItem(qtwi)); ui->m_free_tree_widget->indexOfTopLevelItem(qtwi));
ui->m_link_tree_widget->insertTopLevelItem(0, qtwi); ui->m_link_tree_widget->insertTopLevelItem(0, qtwi);
if(m_live_edit) if(m_live_edit)
apply(); apply();
} }