QPushButton * del,
QPushButton * up,
QPushButton * down,
- QAbstractListModel * amod,
+ QAbstractItemModel * amod,
QAbstractItemModel * smod,
int const main_sel_col)
: QObject(parent), availableLV(avail), selectedLV(sel),
connect(availableLV->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(availableChanged(QItemSelection, QItemSelection)));
+ connect(availableLV->selectionModel(),
+ SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(updateButtons()));
connect(selectedLV->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this, SLOT(selectedChanged(QItemSelection, QItemSelection)));
+ connect(selectedLV->selectionModel(),
+ SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(updateButtons()));
connect(selectedLV->itemDelegate(), SIGNAL(commitData(QWidget*)),
this, SLOT(selectedEdited()));
connect(addPB, SIGNAL(clicked()),
}
+void GuiSelectionManager::updateButtons()
+{
+ update();
+ updateHook();
+}
+
+
QModelIndex GuiSelectionManager::getSelectedIndex(int const c) const
{
- QModelIndexList avail = availableLV->selectionModel()->selectedIndexes();
+ QModelIndexList avail = availableLV->selectionModel()->selectedRows(c);
QModelIndexList sel = selectedLV->selectionModel()->selectedRows(c);
bool const have_avl = !avail.isEmpty();
bool const have_sel = !sel.isEmpty();
if (selIdx.isEmpty())
return;
QModelIndex idx = selIdx.first();
- selectedModel->removeRow(idx.row());
- selectionChanged(); //signal
+ int const row = idx.row();
int nrows = selectedLV->model()->rowCount();
- if (idx.row() == nrows) //was last item on list
- idx = idx.sibling(idx.row() - 1, idx.column());
- if (nrows > 1)
- selectedLV->setCurrentIndex(idx);
- else if (nrows == 1)
+ selectedModel->removeRow(row);
+ selectionChanged(); //signal
+
+ // select previous item
+ if (nrows > 0)
+ selectedLV->setCurrentIndex(selectedLV->model()->index(row - 1, 0));
+ else if (nrows == 0)
selectedLV->setCurrentIndex(selectedLV->model()->index(0, 0));
- selectedHasFocus_ = (nrows > 0);
+ selectedHasFocus_ = (nrows > 1);
updateHook();
}