]> git.lyx.org Git - features.git/commitdiff
Refactor a bit. This will be needed a bit later.
authorRichard Heck <rgheck@comcast.net>
Wed, 24 Mar 2010 12:04:24 +0000 (12:04 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 24 Mar 2010 12:04:24 +0000 (12:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33849 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/GuiSelectionManager.cpp
src/frontends/qt4/GuiSelectionManager.h

index 35f7e913a7fc835638c4e4251d2a52fa78cdb452..cc5dafcc57e6c873806e4c9f3d6e48ce9154d927 100644 (file)
@@ -198,17 +198,8 @@ void GuiCitation::updateControls()
 // 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"]));
@@ -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();
        return selected_model_.stringList().contains(str);
index 4d172bc35d890cb52de14e27d6ec9f50f9edcfaf..ca408b9cd757fda397ec522235a87110a8787180 100644 (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()
 {
        int const arows = availableModel->rowCount();
index ddb7d2c665dcd85de5e28b4a5d694dc1b7f61733..9c2432460b61543f79b7b52c6481c08b9c1efd6e 100644 (file)
@@ -60,7 +60,10 @@ public:
        /// 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.