void SettingsWidget::moveModule() { if (QToolButton *tB = qobject_cast<QToolButton *>(sender())) { const bool moveDown = tB->arrowType() == Qt::DownArrow; const int idx = tB->property("idx").toInt(); QListWidget *mL = page2ModulesList[idx]->list; int row = mL->currentRow(); if (row > -1) { QListWidgetItem *item = mL->takeItem(row); mL->clearSelection(); if (moveDown) ++row; else --row; mL->insertItem(row, item); mL->setCurrentItem(item); } } }
void CQReportDefinition::btnDeleteClicked() { QListWidget * pList = static_cast< QListWidget * >(mpReportSectionTab->currentPage()); QListWidgetItem * pNewSelection = NULL; int i, multipleSelection; for (i = pList->count() - 1, multipleSelection = 0; 0 <= i; i--) if (pList->item(i)->isSelected()) { delete pList->takeItem(i); if (!pNewSelection && i < pList->count()) { pNewSelection = pList->item(i); // We select the next. } multipleSelection++; } if (multipleSelection == 0) return; // Nothing selected, mChanged = true; pList->clearSelection(); if (multipleSelection > 1) return; // Only one item was select and we move the selection to the next if (!pNewSelection && pList->count()) // We have removed item at the end. pNewSelection = pList->item(pList->count() - 1); // pNewSelection is NULL if the list is empty if (pNewSelection) { pNewSelection->setSelected(true); } return; }