]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCitation.cpp
Initialize class members to please coverity
[lyx.git] / src / frontends / qt4 / GuiCitation.cpp
index 2178dd1101722fcb4887e50aaaa3f6e7a8c6d9a6..c1694bb539eba1e4d99eff955fd0ee8a0bfb0926 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "GuiApplication.h"
 #include "GuiSelectionManager.h"
-#include "LyXToolBox.h"
 #include "qt_helpers.h"
 
 #include "Buffer.h"
@@ -127,6 +126,8 @@ GuiCitation::GuiCitation(GuiView & lv)
                this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
        connect(starredCB, SIGNAL(clicked()),
                this, SLOT(updateStyles()));
+       connect(literalCB, SIGNAL(clicked()),
+               this, SLOT(changed()));
        connect(forceuppercaseCB, SIGNAL(clicked()),
                this, SLOT(updateStyles()));
        connect(textBeforeED, SIGNAL(textChanged(QString)),
@@ -138,7 +139,7 @@ GuiCitation::GuiCitation(GuiView & lv)
        connect(textAfterED, SIGNAL(returnPressed()),
                this, SLOT(on_okPB_clicked()));
 
-       selectionManager = new GuiSelectionManager(availableLV, selectedLV,
+       selectionManager = new GuiSelectionManager(this, availableLV, selectedLV,
                        addPB, deletePB, upPB, downPB, &available_model_, &selected_model_, 1);
        connect(selectionManager, SIGNAL(selectionChanged()),
                this, SLOT(setCitedKeys()));
@@ -153,6 +154,13 @@ GuiCitation::GuiCitation(GuiView & lv)
                this, SLOT(filterChanged(QString)));
        connect(filter_, SIGNAL(returnPressed()),
                this, SLOT(filterPressed()));
+#if (QT_VERSION < 0x050000)
+       connect(filter_, SIGNAL(downPressed()),
+               availableLV, SLOT(setFocus()));
+#else
+       connect(filter_, &FancyLineEdit::downPressed,
+               availableLV, [=](){ focusAndHighlight(availableLV); });
+#endif
        connect(regexp_, SIGNAL(triggered()),
                this, SLOT(regexChanged()));
        connect(casesense_, SIGNAL(triggered()),
@@ -170,12 +178,6 @@ GuiCitation::GuiCitation(GuiView & lv)
 }
 
 
-GuiCitation::~GuiCitation()
-{
-       delete selectionManager;
-}
-
-
 void GuiCitation::closeEvent(QCloseEvent * e)
 {
        clearSelection();
@@ -248,6 +250,10 @@ void GuiCitation::updateControls(BiblioInfo const & bi)
 {
        QModelIndex idx = selectionManager->getSelectedIndex(1);
        updateInfo(bi, idx);
+       int i = citationStyleCO->currentIndex();
+       if (i == -1)
+               i = 0;
+       updateFormatting(citeStyles_[i]);
        selectionManager->update();
 }
 
@@ -270,29 +276,44 @@ void GuiCitation::updateFormatting(CitationStyle currentStyle)
        selectedLV->horizontalHeader()->setVisible(qualified);
        selectedLV->setColumnHidden(0, !qualified);
        selectedLV->setColumnHidden(2, !qualified);
+       bool const haveSelection = rows > 0;
        if (qualified) {
                textBeforeLA->setText(qt_("General text befo&re:"));
                textAfterLA->setText(qt_("General &text after:"));
                textBeforeED->setToolTip(qt_("Text that precedes the whole reference list. "
-                                            "For text that precedes individual items, double-click on the respective entry above."));
+                                            "For text that precedes individual items, "
+                                            "double-click on the respective entry above."));
                textAfterLA->setToolTip(qt_("General &text after:"));
                textAfterED->setToolTip(qt_("Text that follows the whole reference list. "
-                                            "For text that follows individual items, double-click on the respective entry above."));
+                                            "For text that follows individual items, "
+                                            "double-click on the respective entry above."));
        } else {
                textBeforeLA->setText(qt_("Text befo&re:"));
-               textBeforeED->setToolTip(qt_("Text that precedes the reference (e.g., \"cf.\")"));
+               if (textbefore && haveSelection)
+                       textBeforeED->setToolTip(qt_("Text that precedes the reference (e.g., \"cf.\")"));
+               else
+                       textBeforeED->setToolTip(qt_("Text that precedes the reference (e.g., \"cf.\"), "
+                                                    "if the current citation style supports this."));
                textAfterLA->setText(qt_("&Text after:"));
-               textAfterED->setToolTip(qt_("Text that follows the reference (e.g., pages)"));
+               if (textafter && haveSelection)
+                       textAfterED->setToolTip(qt_("Text that follows the reference (e.g., pages)"));
+               else
+                       textAfterED->setToolTip(qt_("Text that follows the reference (e.g., pages), "
+                                                   "if the current citation style supports this."));
        }
 
-       bool const haveSelection = rows > 0;
-
        forceuppercaseCB->setEnabled(force && haveSelection);
+       if (force && haveSelection)
+               forceuppercaseCB->setToolTip("Force upper case in names (\"Del Piero\", not \"del Piero\").");
+       else
+               forceuppercaseCB->setToolTip("Force upper case in names (\"Del Piero\", not \"del Piero\"), "
+                                            "if the current citation style supports this.");
        starredCB->setEnabled(full && haveSelection);
        textBeforeED->setEnabled(textbefore && haveSelection);
        textBeforeLA->setEnabled(textbefore && haveSelection);
        textAfterED->setEnabled(textafter && haveSelection);
        textAfterLA->setEnabled(textafter && haveSelection);
+       literalCB->setEnabled(textbefore || textafter);
        citationStyleCO->setEnabled(haveSelection);
        citationStyleLA->setEnabled(haveSelection);
 
@@ -317,7 +338,11 @@ void GuiCitation::updateFormatting(CitationStyle currentStyle)
        } else {
                // This is the default meaning of the starred commands
                starredCB->setText(qt_("All aut&hors"));
-               starredCB->setToolTip(qt_("Always list all authors (rather than using \"et al.\")"));
+               if (full && haveSelection)
+                       starredCB->setToolTip(qt_("Always list all authors (rather than using \"et al.\")"));
+               else
+                       starredCB->setToolTip(qt_("Always list all authors (rather than using \"et al.\"), "
+                                                 "if the current citation style supports this."));
        }
 }
 
@@ -585,6 +610,7 @@ void GuiCitation::applyParams(int const choice, bool full, bool force,
                params_["pretextlist"] = getStringFromVector(getPreTexts(), from_ascii("\t"));
                params_["posttextlist"] = getStringFromVector(getPostTexts(), from_ascii("\t"));
        }
+       params_["literal"] = literalCB->isChecked() ? from_ascii("true") : from_ascii("false");
        dispatchParams();
 }
 
@@ -726,6 +752,7 @@ void GuiCitation::init()
                documentBuffer().params().fullAuthorList());
        textBeforeED->setText(toqstr(params_["before"]));
        textAfterED->setText(toqstr(params_["after"]));
+       literalCB->setChecked(params_["literal"] == "true");
 
        setPreTexts(getVectorFromString(params_["pretextlist"], from_ascii("\t")));
        setPostTexts(getVectorFromString(params_["posttextlist"], from_ascii("\t")));
@@ -1025,7 +1052,7 @@ void GuiCitation::restoreSession()
        QSettings settings;
        regexp_->setChecked(settings.value(sessionKey() + "/regex").toBool());
        casesense_->setChecked(settings.value(sessionKey() + "/casesensitive").toBool());
-       instant_->setChecked(settings.value(sessionKey() + "/autofind").toBool());
+       instant_->setChecked(settings.value(sessionKey() + "/autofind", true).toBool());
        style_ = settings.value(sessionKey() + "/citestyle").toInt();
        updateFilterHint();
 }