From 2c832e6578ae146a2b51967cbc78cd640959f196 Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Fri, 15 Dec 2006 09:58:44 +0000 Subject: [PATCH] more cleanup: - clear selected keys on ok/cancel - update info when navigating with keyboard - add clear search button - don't allow search strings that return empty selection git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16277 a592a061-630c-0410-9148-cb99ea01b6c8 --- Status.15x | 8 - src/frontends/qt4/QCitation.C | 14 +- src/frontends/qt4/QCitation.h | 6 +- src/frontends/qt4/QCitationDialog.C | 63 +++- src/frontends/qt4/QCitationDialog.h | 2 + src/frontends/qt4/ui/QCitationUi.ui | 429 ++++++++++++++-------------- 6 files changed, 289 insertions(+), 233 deletions(-) diff --git a/Status.15x b/Status.15x index 767895eb84..2324c68c3d 100644 --- a/Status.15x +++ b/Status.15x @@ -92,14 +92,6 @@ DIALOGS * If you try to view a document as postscript that cannot be typeset because of LaTeX errors and export to LaTeX afterwards you will get the old error list again, although the export succeded. - -* Citation dialog: Create some citation; open the citation dialog a second time for - another new citation => the selected entry from the first citations is - already selected for the second citation (which is wrong) - -* Citation dialog: If you use the cursor up/down keys to browse through the - list of available citations, the "preview" (in the middle of the dialog) - is not updated MATH CONTROL PANEL diff --git a/src/frontends/qt4/QCitation.C b/src/frontends/qt4/QCitation.C index dbd5d7333d..d9dba70a58 100644 --- a/src/frontends/qt4/QCitation.C +++ b/src/frontends/qt4/QCitation.C @@ -56,7 +56,7 @@ QCitation::QCitation(Dialog & parent) void QCitation::apply(int const choice, bool const full, bool const force, QString before, QString after) { - if (!isValid()) + if (selected_keys_.rowCount() == 0) return; vector const & styles = @@ -74,6 +74,12 @@ void QCitation::apply(int const choice, bool const full, bool const force, } +void QCitation::clearSelection() +{ + selected_keys_.setStringList(QStringList()); +} + + QString QCitation::textBefore() { return toqstr(params()["before"]); @@ -101,12 +107,6 @@ void QCitation::updateModel() } -bool QCitation::isValid() -{ - return selected_keys_.rowCount() > 0; -} - - void QCitation::findKey(QString const & str) { QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive); diff --git a/src/frontends/qt4/QCitation.h b/src/frontends/qt4/QCitation.h index c6131713ff..92948ff272 100644 --- a/src/frontends/qt4/QCitation.h +++ b/src/frontends/qt4/QCitation.h @@ -43,6 +43,9 @@ public: /// Get key description QString getKeyInfo(QString const &); + /// Clear selected keys + void clearSelection(); + /// Find keys containing the string (not case-sens) void findKey(QString const &); @@ -61,9 +64,6 @@ public: /// List of example cite strings QStringList citationStyles(int); - /// Check whether there are keys to select - virtual bool isValid(); - /// Set the Params variable for the Controller. virtual void apply(int const choice, bool const full, bool const force, QString before, QString after); diff --git a/src/frontends/qt4/QCitationDialog.C b/src/frontends/qt4/QCitationDialog.C index abf88739d7..d10365ae9c 100644 --- a/src/frontends/qt4/QCitationDialog.C +++ b/src/frontends/qt4/QCitationDialog.C @@ -57,6 +57,14 @@ QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form) this, SLOT(changed())); connect(textAfterED, SIGNAL(textChanged(const QString&)), this, SLOT(changed())); + connect(clearPB, SIGNAL(clicked()), + findLE, SLOT(clear())); + connect(availableLV->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &))); + connect(selectedLV->selectionModel(), + SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), + this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &))); } @@ -100,12 +108,14 @@ bool QCitationDialog::isVisible() const void QCitationDialog::on_okPB_clicked() { apply(); + form_->clearSelection(); accept(); } void QCitationDialog::on_cancelPB_clicked() { + form_->clearSelection(); accept(); } @@ -126,12 +136,12 @@ void QCitationDialog::update() { form_->updateModel(); - QModelIndex idxa = availableLV->currentIndex(); - if (!idxa.isValid()) + QModelIndex const idxa = availableLV->currentIndex(); + if (form_->available()->rowCount() > 0 && !idxa.isValid()) availableLV->setCurrentIndex(availableLV->model()->index(0,0)); - QModelIndex idx = selectedLV->currentIndex(); - if (form_->isValid() && !idx.isValid()) { + QModelIndex const idx = selectedLV->currentIndex(); + if (form_->selected()->rowCount() > 0 && !idx.isValid()) { selectedLV->setCurrentIndex(selectedLV->model()->index(0,0)); updateInfo(selectedLV->currentIndex()); } else @@ -158,6 +168,7 @@ void QCitationDialog::updateStyle() fulllistCB->setEnabled(natbib_engine); forceuppercaseCB->setEnabled(natbib_engine); textBeforeED->setEnabled(!basic_engine); + textBeforeLA->setEnabled(!basic_engine); string const & command = form_->params().getCmdName(); @@ -200,10 +211,12 @@ void QCitationDialog::fillStyles() return; } - if (selectedLV->selectionModel()->selectedIndexes().empty()) + int curr = selectedLV->model()->rowCount() - 1; + if (curr < 0) return; - - int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem(); + + if (!selectedLV->selectionModel()->selectedIndexes().empty()) + curr = selectedLV->selectionModel()->selectedIndexes()[0].row(); QStringList sty = form_->citationStyles(curr); @@ -213,6 +226,9 @@ void QCitationDialog::fillStyles() citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine); citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine); + if (sty.isEmpty() || basic_engine) + return; + citationStyleCO->insertItems(0, sty); if (orig != -1 && orig < citationStyleCO->count()) @@ -254,12 +270,37 @@ void QCitationDialog::updateInfo(const QModelIndex & idx) void QCitationDialog::on_selectedLV_clicked(const QModelIndex & idx) { + availableLV->selectionModel()->clear(); + updateInfo(idx); changed(); } + +void QCitationDialog::selectedChanged(const QModelIndex & idx, const QModelIndex &) +{ + if (!idx.isValid()) + return; + + updateInfo(idx); + changed(); +} + + void QCitationDialog::on_availableLV_clicked(const QModelIndex & idx) { + selectedLV->selectionModel()->clear(); + + updateInfo(idx); + setButtons(); +} + + +void QCitationDialog::availableChanged(const QModelIndex & idx, const QModelIndex &) +{ + if (!idx.isValid()) + return; + updateInfo(idx); setButtons(); } @@ -322,7 +363,15 @@ void QCitationDialog::on_downPB_clicked() void QCitationDialog::on_findLE_textChanged(const QString & text) { + clearPB->setDisabled(text.isEmpty()); + if (text.isEmpty()) + findLE->setFocus(); + form_->findKey(text); + if (form_->found()->rowCount() == 0) { + findLE->backspace(); + return; + } availableLV->setModel(form_->found()); changed(); } diff --git a/src/frontends/qt4/QCitationDialog.h b/src/frontends/qt4/QCitationDialog.h index 46fd7ffe0b..f1d89e5440 100644 --- a/src/frontends/qt4/QCitationDialog.h +++ b/src/frontends/qt4/QCitationDialog.h @@ -57,8 +57,10 @@ protected Q_SLOTS: void on_downPB_clicked(); void on_findLE_textChanged(const QString & text); void on_selectedLV_clicked(const QModelIndex &); + void selectedChanged(const QModelIndex &, const QModelIndex &); void on_availableLV_clicked(const QModelIndex &); void on_availableLV_activated(const QModelIndex &); + void availableChanged(const QModelIndex &, const QModelIndex &); virtual void changed(); /// check whether key is already selected bool isSelected(const QModelIndex &); diff --git a/src/frontends/qt4/ui/QCitationUi.ui b/src/frontends/qt4/ui/QCitationUi.ui index a7f5d2ce9e..16ebeb282d 100644 --- a/src/frontends/qt4/ui/QCitationUi.ui +++ b/src/frontends/qt4/ui/QCitationUi.ui @@ -26,14 +26,230 @@ true - + 9 6 - + + + + 0 + + + 6 + + + + + &Find: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + selectedLV + + + + + + + + + + + + + + false + + + <- Clear + + + + + + + + + 0 + + + 6 + + + + + &Restore + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &OK + + + true + + + true + + + + + + + A&pply + + + + + + + &Cancel + + + false + + + + + + + + + Formatting + + + true + + + + 9 + + + 6 + + + + + + 3 + 0 + 0 + 0 + + + + Natbib citation style to use + + + + + + + Citation &style: + + + citationStyleCO + + + + + + + List all authors + + + &Full author list + + + + + + + Force upper case in citation + + + Force &upper case + + + + + + + &Text after: + + + textAfterED + + + + + + + + 5 + 0 + 0 + 0 + + + + Text to place after citation + + + + + + + Text &before: + + + textAfterED + + + + + + + + 5 + 0 + 0 + 0 + + + + Text to place before citation + + + + + + + + + + 0 @@ -152,215 +368,9 @@ - - - - 0 - - - 6 - - - - - &Find: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - selectedLV - - - - - - - - - - - - - - - - - - - Formatting - - - - 9 - - - 6 - - - - - - 3 - 0 - 0 - 0 - - - - Natbib citation style to use - - - - - - - Citation &style: - - - citationStyleCO - - - - - - - List all authors - - - &Full author list - - - - - - - Force upper case in citation - - - Force &upper case - - - - - - - &Text after: - - - textAfterED - - - - - - - - 5 - 0 - 0 - 0 - - - - Text to place after citation - - - - - - - Text &before: - - - textAfterED - - - - - - - - 5 - 0 - 0 - 0 - - - - Text to place before citation - - - - - - - - - - 0 - - - 6 - - - - - &Restore - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &OK - - - true - - - true - - - - - - - A&pply - - - - - - - &Cancel - - - false - - - - - - - qt_helpers.h - availableLV selectedLV @@ -380,6 +390,9 @@ applyPB cancelPB + + qt_helpers.h +