diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index c2d35a3b1b..234219fa31 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -105,7 +105,7 @@ GuiCitation::GuiCitation(GuiView & lv) connect(this, SIGNAL(rejected()), this, SLOT(cleanUp())); selectionManager = new GuiSelectionManager(availableLV, selectedLV, - addPB, deletePB, upPB, downPB, available(), selected()); + addPB, deletePB, upPB, downPB, &available_model_, &selected_model_); connect(selectionManager, SIGNAL(selectionChanged()), this, SLOT(setCitedKeys())); connect(selectionManager, SIGNAL(updateHook()), @@ -210,8 +210,8 @@ void GuiCitation::updateControls() } setButtons(); - textBeforeED->setText(textBefore()); - textAfterED->setText(textAfter()); + textBeforeED->setText(toqstr(params_["before"])); + textAfterED->setText(toqstr(params_["after"])); fillStyles(); updateStyle(); } @@ -279,7 +279,7 @@ void GuiCitation::fillStyles() citationStyleCO->clear(); - QStringList selected_keys = selected()->stringList(); + QStringList selected_keys = selected_model_.stringList(); if (selected_keys.empty()) { citationStyleCO->setEnabled(false); citationStyleLA->setEnabled(false); @@ -313,7 +313,7 @@ void GuiCitation::fillFields() fieldsCO->blockSignals(true); int const oldIndex = fieldsCO->currentIndex(); fieldsCO->clear(); - QStringList const & fields = getFieldsAsQStringList(); + QStringList const fields = to_qstring_list(bibInfo().getFields()); fieldsCO->insertItem(0, qt_("All Fields")); fieldsCO->insertItem(1, qt_("Keys")); fieldsCO->insertItems(2, fields); @@ -328,7 +328,7 @@ void GuiCitation::fillEntries() entriesCO->blockSignals(true); int const oldIndex = entriesCO->currentIndex(); entriesCO->clear(); - QStringList const & entries = getEntriesAsQStringList(); + QStringList const entries = to_qstring_list(bibInfo().getEntries()); entriesCO->insertItem(0, qt_("All Entry Types")); entriesCO->insertItems(1, entries); if (oldIndex != -1 && oldIndex < entriesCO->count()) @@ -340,7 +340,7 @@ void GuiCitation::fillEntries() bool GuiCitation::isSelected(const QModelIndex & idx) { QString const str = idx.data().toString(); - return selected()->stringList().contains(str); + return selected_model_.stringList().contains(str); } @@ -355,11 +355,14 @@ void GuiCitation::setButtons() void GuiCitation::updateInfo(QModelIndex const & idx) { - if (idx.isValid()) { - QString const keytxt = getKeyInfo(idx.data().toString()); - infoML->document()->setPlainText(keytxt); - } else + if (!idx.isValid() || bibInfo().empty()) { infoML->document()->clear(); + return; + } + + QString const keytxt = toqstr( + bibInfo().getInfo(qstring_to_ucs4(idx.data().toString()))); + infoML->document()->setPlainText(keytxt); } @@ -367,7 +370,7 @@ void GuiCitation::findText(QString const & text, bool reset) { //"All Fields" and "Keys" are the first two int index = fieldsCO->currentIndex() - 2; - vector const & fields = availableFields(); + vector const & fields = bibInfo().getFields(); docstring field; if (index <= -1 || index >= int(fields.size())) @@ -381,7 +384,7 @@ void GuiCitation::findText(QString const & text, bool reset) //"All Entry Types" is first. index = entriesCO->currentIndex() - 1; - vector const & entries = availableEntries(); + vector const & entries = bibInfo().getEntries(); docstring entry_type; if (index < 0 || index >= int(entries.size())) entry_type = from_ascii(""); @@ -503,22 +506,10 @@ void GuiCitation::clearSelection() } -QString GuiCitation::textBefore() -{ - return toqstr(params_["before"]); -} - - -QString GuiCitation::textAfter() -{ - return toqstr(params_["after"]); -} - - void GuiCitation::init() { // Make the list of all available bibliography keys - all_keys_ = to_qstring_list(availableKeys()); + all_keys_ = to_qstring_list(bibInfo().getKeys()); available_model_.setStringList(all_keys_); // Ditto for the keys cited in this inset @@ -587,18 +578,6 @@ void GuiCitation::findKey(QString const & str, bool only_keys, } -QStringList GuiCitation::getFieldsAsQStringList() -{ - return to_qstring_list(availableFields()); -} - - -QStringList GuiCitation::getEntriesAsQStringList() -{ - return to_qstring_list(availableEntries()); -} - - QStringList GuiCitation::citationStyles(int sel) { docstring const key = qstring_to_ucs4(cited_keys_[sel]); @@ -606,12 +585,6 @@ QStringList GuiCitation::citationStyles(int sel) } -QString GuiCitation::getKeyInfo(QString const & sel) -{ - return toqstr(getInfo(qstring_to_ucs4(sel))); -} - - void GuiCitation::setCitedKeys() { cited_keys_ = selected_model_.stringList(); @@ -634,24 +607,6 @@ void GuiCitation::clearParams() } -vector GuiCitation::availableKeys() const -{ - return bibInfo().getKeys(); -} - - -vector GuiCitation::availableFields() const -{ - return bibInfo().getFields(); -} - - -vector GuiCitation::availableEntries() const -{ - return bibInfo().getEntries(); -} - - void GuiCitation::filterByEntryType( vector & keyVector, docstring entry_type) { @@ -680,15 +635,6 @@ CiteEngine GuiCitation::citeEngine() const } -docstring GuiCitation::getInfo(docstring const & key) const -{ - if (bibInfo().empty()) - return docstring(); - - return bibInfo().getInfo(key); -} - - // Escape special chars. // All characters are literals except: '.|*?+(){}[]^$\' // These characters are literals when preceded by a "\", which is done here diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index 52b6b315d6..3dd2143e9e 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -42,23 +42,6 @@ public: GuiCitation(GuiView & lv); /// ~GuiCitation(); - /// - void applyView(); - - void updateView() {} - -private: - /// - void showEvent(QShowEvent * e); - /// - void closeEvent(QCloseEvent * e); - /// prepares a call to GuiCitation::searchKeys when we - /// are ready to search the BibTeX entries - void findText(QString const & text, bool reset = false); - /// check whether key is already selected - bool isSelected(const QModelIndex &); - /// update the display of BibTeX information - void updateInfo(QModelIndex const &); private Q_SLOTS: void cleanUp(); @@ -80,7 +63,33 @@ private Q_SLOTS: /// performs a limited update, suitable for internal call void updateControls(); + private: + /// Dialog inherited methods + //@{ + void applyView(); + void updateView() {} + bool initialiseParams(std::string const & data); + void clearParams(); + void dispatchParams(); + bool isBufferDependent() const { return true; } + /** Disconnect from the inset when the Apply button is pressed. + * Allows easy insertion of multiple citations. + */ + bool disconnectOnApply() const { return true; } + //@} + + /// + void showEvent(QShowEvent * e); + /// + void closeEvent(QCloseEvent * e); + /// prepares a call to GuiCitation::searchKeys when we + /// are ready to search the BibTeX entries + void findText(QString const & text, bool reset = false); + /// check whether key is already selected + bool isSelected(const QModelIndex &); + /// update the display of BibTeX information + void updateInfo(QModelIndex const &); /// enable/disable buttons void setButtons(); /// fill the styles combo @@ -93,29 +102,10 @@ private: void updateStyle(); /// set the formatting widgets void updateFormatting(CiteStyle currentStyle); - /// last used citation style - int style_; - - GuiSelectionManager * selectionManager; - /// void init(); - /// Available keys - QStringListModel * available() { return &available_model_; } - /// Selected keys - QStringListModel * selected() { return &selected_model_; } - /// Text before cite - QString textBefore(); - /// Text after cite - QString textAfter(); - /// Get key description - QString getKeyInfo(QString const &); /// Clear selected keys void clearSelection(); - /// Return a list of available fields - QStringList getFieldsAsQStringList(); - /// Return a list of available fields - QStringList getEntriesAsQStringList(); /// Find keys containing a string. void findKey( @@ -134,47 +124,13 @@ private: /// Set the Params variable for the Controller. void apply(int const choice, bool const full, bool const force, QString before, QString after); - /// - bool initialiseParams(std::string const & data); - /// clean-up on hide. - void clearParams(); - /// clean-up on hide. - void dispatchParams(); - /// - bool isBufferDependent() const { return true; } -private: - /// available keys. - QStringListModel available_model_; - /// selected keys. - QStringListModel selected_model_; - /// All keys. - QStringList all_keys_; - /// Cited keys. - QStringList cited_keys_; - /// - InsetCommandParams params_; - - /** Disconnect from the inset when the Apply button is pressed. - * Allows easy insertion of multiple citations. - */ - bool disconnectOnApply() const { return true; } - - /// \return the list of all available bibliography keys. - std::vector availableKeys() const; - /// \return the list of all used BibTeX fields - std::vector availableFields() const; - /// \return the list of all used BibTeX entry types - std::vector availableEntries() const; /// void filterByEntryType( std::vector & keyVector, docstring entryType); /// CiteEngine citeEngine() const; - /// \return information for this key. - docstring getInfo(docstring const & key) const; - /// Search a given string within the passed keys. /// \return the vector of matched keys. std::vector searchKeys( @@ -186,9 +142,23 @@ private: bool regex = false //< \set to true if \c search_expression is a regex ); // -private: /// The BibTeX information available to the dialog BiblioInfo const & bibInfo() const; + + /// last used citation style + int style_; + /// + GuiSelectionManager * selectionManager; + /// available keys. + QStringListModel available_model_; + /// selected keys. + QStringListModel selected_model_; + /// All keys. + QStringList all_keys_; + /// Cited keys. + QStringList cited_keys_; + /// + InsetCommandParams params_; }; } // namespace frontend