MCPcopy Create free account
hub / github.com/LeFroid/Viper-Browser / onDeleteButtonClicked

Method onDeleteButtonClicked

src/ui/user_scripts/UserScriptWidget.cpp:55–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55void UserScriptWidget::onDeleteButtonClicked()
56{
57 QModelIndexList selection = ui->tableViewScripts->selectionModel()->selectedIndexes();
58 if (selection.empty())
59 return;
60
61 // Get user confirmation before deleting items
62 QMessageBox::StandardButton answer =
63 QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to delete the selected script(s)?"),
64 QMessageBox::Yes|QMessageBox::No);
65 if (answer == QMessageBox::No)
66 return;
67
68 // Get rows from selection without duplicates (in case multiple columns of same row(s) are selected)
69 std::vector<int> selectedRows;
70 for (const QModelIndex &idx : selection)
71 {
72 int row = idx.row();
73 auto it = std::find(selectedRows.begin(), selectedRows.end(), row);
74 if (it == selectedRows.end())
75 selectedRows.push_back(row);
76 }
77 // Sort rows in descending order
78 std::sort(selectedRows.begin(), selectedRows.end(), std::greater<int>());
79
80 // Remove scripts
81 UserScriptModel *model = qobject_cast<UserScriptModel*>(ui->tableViewScripts->model());
82 for (int row : selectedRows)
83 model->removeRow(row);
84}
85
86void UserScriptWidget::onEditButtonClicked()
87{

Callers

nothing calls this directly

Calls 2

beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected