// two methods, though they should be divisible.
void GuiCitation::updateControls(BiblioInfo const & bi)
{
- if (selectionManager->selectedFocused()) {
- if (selectedLV->selectionModel()->selectedIndexes().isEmpty())
- updateInfo(bi, availableLV->currentIndex());
- else
- updateInfo(bi, selectedLV->currentIndex());
- } else {
- if (availableLV->selectionModel()->selectedIndexes().isEmpty())
- updateInfo(bi, QModelIndex());
- else
- updateInfo(bi, availableLV->currentIndex());
- }
+ QModelIndex idx = selectionManager->getSelectedIndex();
+ updateInfo(bi, idx);
setButtons();
textBeforeED->setText(toqstr(params_["before"]));
}
-bool GuiCitation::isSelected(const QModelIndex & idx)
+bool GuiCitation::isSelected(QModelIndex const & idx)
{
QString const str = idx.data().toString();
return selected_model_.stringList().contains(str);
}
+QModelIndex GuiSelectionManager::getSelectedIndex() const
+{
+ bool const have_avl =
+ !availableLV->selectionModel()->selectedIndexes().isEmpty();
+ bool const have_sel =
+ !selectedLV->selectionModel()->selectedIndexes().isEmpty();
+
+ if (selectedFocused()) {
+ if (have_sel)
+ return selectedLV->currentIndex();
+ if (have_avl)
+ return availableLV->currentIndex();
+ }
+ else { // available has focus
+ if (have_avl)
+ return availableLV->currentIndex();
+ if (have_sel)
+ return selectedLV->currentIndex();
+ }
+ return QModelIndex();
+}
+
+
void GuiSelectionManager::updateAddPB()
{
int const arows = availableModel->rowCount();
/// to be used, for example, in displaying information about a
/// highlighted item: should it be the highlighted available item
/// or the highlighted selected item that is displayed?
- bool selectedFocused() { return selectedHasFocus_; };
+ bool selectedFocused() const { return selectedHasFocus_; };
+ /// Returns the selected index. Note that this will depend upon
+ /// selectedFocused().
+ QModelIndex getSelectedIndex() const;
Q_SIGNALS:
/// Emitted when the list of selected items has changed.