Refactor a bit. This will be needed a bit later.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33849 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-03-24 12:04:24 +00:00
parent d95b35dad8
commit adf858ebcc
3 changed files with 30 additions and 13 deletions

View File

@ -198,17 +198,8 @@ void GuiCitation::updateControls()
// two methods, though they should be divisible. // two methods, though they should be divisible.
void GuiCitation::updateControls(BiblioInfo const & bi) void GuiCitation::updateControls(BiblioInfo const & bi)
{ {
if (selectionManager->selectedFocused()) { QModelIndex idx = selectionManager->getSelectedIndex();
if (selectedLV->selectionModel()->selectedIndexes().isEmpty()) updateInfo(bi, idx);
updateInfo(bi, availableLV->currentIndex());
else
updateInfo(bi, selectedLV->currentIndex());
} else {
if (availableLV->selectionModel()->selectedIndexes().isEmpty())
updateInfo(bi, QModelIndex());
else
updateInfo(bi, availableLV->currentIndex());
}
setButtons(); setButtons();
textBeforeED->setText(toqstr(params_["before"])); textBeforeED->setText(toqstr(params_["before"]));
@ -344,7 +335,7 @@ void GuiCitation::fillEntries(BiblioInfo const & bi)
} }
bool GuiCitation::isSelected(const QModelIndex & idx) bool GuiCitation::isSelected(QModelIndex const & idx)
{ {
QString const str = idx.data().toString(); QString const str = idx.data().toString();
return selected_model_.stringList().contains(str); return selected_model_.stringList().contains(str);

View File

@ -92,6 +92,29 @@ void GuiSelectionManager::update()
} }
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() void GuiSelectionManager::updateAddPB()
{ {
int const arows = availableModel->rowCount(); int const arows = availableModel->rowCount();

View File

@ -60,7 +60,10 @@ public:
/// to be used, for example, in displaying information about a /// to be used, for example, in displaying information about a
/// highlighted item: should it be the highlighted available item /// highlighted item: should it be the highlighted available item
/// or the highlighted selected item that is displayed? /// 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: Q_SIGNALS:
/// Emitted when the list of selected items has changed. /// Emitted when the list of selected items has changed.