]> git.lyx.org Git - features.git/commitdiff
Fix bug #6486. Patch inspired by work by John McCabe-Dansted.
authorRichard Heck <rgheck@comcast.net>
Wed, 24 Mar 2010 13:51:47 +0000 (13:51 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 24 Mar 2010 13:51:47 +0000 (13:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33851 a592a061-630c-0410-9148-cb99ea01b6c8

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

index cc5dafcc57e6c873806e4c9f3d6e48ce9154d927..c54a5f2128cc3eb1a4802f314eaed7923739d46f 100644 (file)
@@ -114,8 +114,6 @@ GuiCitation::GuiCitation(GuiView & lv)
        connect(selectionManager, SIGNAL(okHook()),
                this, SLOT(on_okPB_clicked()));
 
-       setFocusProxy(availableLV);
-
        // FIXME: the sizeHint() for this is _way_ too high
        infoML->setFixedHeight(60);
 }
@@ -268,38 +266,40 @@ void GuiCitation::updateStyle()
        updateFormatting(cs.style);
 }
 
+
 // This one needs to be called whenever citationStyleCO needs
 // to be updated---and this would be on anything that changes the
 // selection in selectedLV, or on a general update.
 void GuiCitation::fillStyles(BiblioInfo const & bi)
 {
-       int const oldIndex = citationStyleCO->currentIndex();
-
-       citationStyleCO->clear();
-
        QStringList selected_keys = selected_model_.stringList();
-       if (selected_keys.empty()) {
+       int curr = selectedLV->model()->rowCount() - 1;
+
+       if (curr < 0 || selected_keys.empty()) {
+               citationStyleCO->clear();
                citationStyleCO->setEnabled(false);
                citationStyleLA->setEnabled(false);
                return;
        }
 
-       int curr = selectedLV->model()->rowCount() - 1;
-       if (curr < 0)
-               return;
+       int const oldIndex = citationStyleCO->currentIndex();
 
        if (!selectedLV->selectionModel()->selectedIndexes().empty())
                curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
 
        QStringList sty = citationStyles(bi, curr);
+       citationStyleCO->clear();
 
-       citationStyleCO->setEnabled(!sty.isEmpty());
-       citationStyleLA->setEnabled(!sty.isEmpty());
-
-       if (sty.isEmpty())
+       if (sty.isEmpty()) { 
+               // some error
+               citationStyleCO->setEnabled(false);
+               citationStyleLA->setEnabled(false);
                return;
-
+       }
+       
        citationStyleCO->insertItems(0, sty);
+       citationStyleCO->setEnabled(true);
+       citationStyleLA->setEnabled(true);
 
        if (oldIndex != -1 && oldIndex < citationStyleCO->count())
                citationStyleCO->setCurrentIndex(oldIndex);
@@ -519,6 +519,15 @@ void GuiCitation::init()
        else
                cited_keys_ = str.split(",");
        selected_model_.setStringList(cited_keys_);
+       if (selected_model_.rowCount()) {
+               selectedLV->blockSignals(true);
+               selectedLV->setFocus();
+               QModelIndex idx = selected_model_.index(0, 0);
+               selectedLV->selectionModel()->select(idx, 
+                               QItemSelectionModel::ClearAndSelect);
+               selectedLV->blockSignals(false);
+       } else
+               availableLV->setFocus();
        fillFields(bi);
        fillEntries(bi);
        updateControls(bi);
index 2f202d40f9de6358f9142172c4624c7e305a6f7a..ca30a05e5307b1a057e96bbc71be038f7879414f 100644 (file)
 
 #include "support/debug.h"
 
-#include <QKeyEvent>
+#include <QAbstractListModel>
+#include <QItemSelection>
 #include <QListView>
+#include <QKeyEvent>
 #include <QPushButton>
-#include <QAbstractListModel>
 
 #ifdef KeyPress
 #undef KeyPress
@@ -58,11 +59,17 @@ GuiSelectionManager::GuiSelectionManager(
        availableLV->setModel(amod);
        
        connect(availableLV->selectionModel(),
-               SIGNAL(currentChanged(QModelIndex,QModelIndex)),
+               SIGNAL(currentChanged(QModelIndex, QModelIndex)),
                this, SLOT(availableChanged(QModelIndex, QModelIndex)));
        connect(selectedLV->selectionModel(),
                SIGNAL(currentChanged(QModelIndex, QModelIndex)),
                this, SLOT(selectedChanged(QModelIndex, QModelIndex)));
+       connect(availableLV->selectionModel(),
+               SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+               this, SLOT(availableChanged(QItemSelection, QItemSelection)));
+       connect(selectedLV->selectionModel(),
+               SIGNAL(currentChanged(QItemSelection, QItemSelection)),
+               this, SLOT(selectedChanged(QItemSelection, QItemSelection)));
        connect(addPB, SIGNAL(clicked()), 
                this, SLOT(addPB_clicked()));
        connect(deletePB, SIGNAL(clicked()), 
@@ -181,6 +188,15 @@ bool GuiSelectionManager::isSelected(const QModelIndex & idx)
 }
 
 
+void GuiSelectionManager::availableChanged(QItemSelection const & qis, QItemSelection const &)
+{
+       QModelIndexList il = qis.indexes();
+       if (il.empty()) 
+               return;
+       availableChanged(il.front(), QModelIndex());
+}
+
+
 void GuiSelectionManager::availableChanged(const QModelIndex & idx, const QModelIndex &)
 {
        if (!idx.isValid())
@@ -191,6 +207,15 @@ void GuiSelectionManager::availableChanged(const QModelIndex & idx, const QModel
 }
 
 
+void GuiSelectionManager::selectedChanged(QItemSelection const & qis, QItemSelection const &)
+{
+       QModelIndexList il = qis.indexes();
+       if (il.empty()) 
+               return;
+       selectedChanged(il.front(), QModelIndex());
+}
+
+
 void GuiSelectionManager::selectedChanged(const QModelIndex & idx, const QModelIndex &)
 {
        if (!idx.isValid())
index 9c2432460b61543f79b7b52c6481c08b9c1efd6e..7f188e3705008d90f8c6854dff0d840d991737d3 100644 (file)
@@ -20,6 +20,7 @@ class QListView;
 class QPushButton;
 class QVariant;
 class QAbstractItemView;
+class QItemSelection;
 template <class T, class U> class QMap;
 
 namespace lyx {
@@ -106,9 +107,13 @@ protected:
 
 protected Q_SLOTS:
        ///
-       void availableChanged(const QModelIndex & idx, const QModelIndex &);
+       void availableChanged(QModelIndex const & idx, QModelIndex const &);
        ///
-       void selectedChanged(const QModelIndex & idx, const QModelIndex &);
+       void selectedChanged(QModelIndex const & idx, QModelIndex const &);
+       ///
+       void availableChanged(QItemSelection const & qis, QItemSelection const &);
+       ///
+       void selectedChanged(QItemSelection const & qis, QItemSelection const &);
        ///
        virtual void addPB_clicked();
        ///