From 559da350f085f0fea26d704fb33483f43bede909 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 24 Mar 2010 13:51:47 +0000 Subject: [PATCH] Fix bug #6486. Patch inspired by work by John McCabe-Dansted. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33851 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiCitation.cpp | 39 ++++++++++++++--------- src/frontends/qt4/GuiSelectionManager.cpp | 31 ++++++++++++++++-- src/frontends/qt4/GuiSelectionManager.h | 9 ++++-- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index cc5dafcc57..c54a5f2128 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -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); diff --git a/src/frontends/qt4/GuiSelectionManager.cpp b/src/frontends/qt4/GuiSelectionManager.cpp index 2f202d40f9..ca30a05e53 100644 --- a/src/frontends/qt4/GuiSelectionManager.cpp +++ b/src/frontends/qt4/GuiSelectionManager.cpp @@ -18,10 +18,11 @@ #include "support/debug.h" -#include +#include +#include #include +#include #include -#include #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()) diff --git a/src/frontends/qt4/GuiSelectionManager.h b/src/frontends/qt4/GuiSelectionManager.h index 9c2432460b..7f188e3705 100644 --- a/src/frontends/qt4/GuiSelectionManager.h +++ b/src/frontends/qt4/GuiSelectionManager.h @@ -20,6 +20,7 @@ class QListView; class QPushButton; class QVariant; class QAbstractItemView; +class QItemSelection; template 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(); /// -- 2.39.2