]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiCitation.h
a4784b20ec03b4e24610c9604a203b8fe0f5de1e
[lyx.git] / src / frontends / qt / GuiCitation.h
1 // -*- C++ -*-
2 /**
3  * \file GuiCitation.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  * \author Kalle Dalheimer
9  * \author Abdelrazak Younes
10  * \author Richard Heck
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef GUICITATION_H
16 #define GUICITATION_H
17
18 #include "DialogView.h"
19 #include "ui_CitationUi.h"
20 #include "FancyLineEdit.h"
21
22 #include "insets/InsetCommandParams.h"
23
24 #include "BiblioInfo.h"
25 #include "Citation.h"
26
27 #include <QAbstractListModel>
28 #include <QStandardItemModel>
29 #include <QStringList>
30 #include <QStringListModel>
31
32 namespace lyx {
33
34 class BiblioInfo;
35
36 namespace frontend {
37
38 class GuiSelectionManager;
39
40
41 class GuiCitation : public DialogView, public Ui::CitationUi
42 {
43         Q_OBJECT
44
45 public:
46         ///
47         GuiCitation(GuiView & lv);
48
49 private Q_SLOTS:
50         void on_buttonBox_accepted();
51         void on_buttonBox_rejected();
52         void on_buttonBox_clicked(QAbstractButton *);
53         void on_literalCB_clicked();
54         void filterPressed();
55         void filterChanged(const QString & text);
56         void on_fieldsCO_currentIndexChanged(int index);
57         void on_entriesCO_currentIndexChanged(int index);
58         void on_citationStyleCO_currentIndexChanged(int index);
59         void resetFilter();
60         void caseChanged();
61         void regexChanged();
62         void instantChanged(bool checked);
63         void changed();
64         /// set the citation keys, mark as changed
65         void setCitedKeys();
66         /// update the styles for the style combo, mark as changed
67         void updateStyles();
68         /// performs a limited update, suitable for internal call
69         void updateControls();
70
71
72 private:
73         /// Dialog inherited methods
74         //@{
75         void applyView() override;
76         void updateView() override {}
77         bool initialiseParams(std::string const & data) override;
78         void clearParams() override;
79         void dispatchParams() override;
80         bool isBufferDependent() const override { return true; }
81         void saveSession(QSettings & settings) const override;
82         void restoreSession() override;
83         /** Disconnect from the inset when the Apply button is pressed.
84          *  Allows easy insertion of multiple citations.
85          */
86         bool disconnectOnApply() const override { return true; }
87         //@}
88
89         ///
90         void showEvent(QShowEvent * e);
91         ///
92         void closeEvent(QCloseEvent * e);
93         /// prepares a call to GuiCitation::searchKeys when we
94         /// are ready to search the BibTeX entries
95         void findText(QString const & text, bool reset = false);
96         /// check whether key is already selected
97         bool isSelected(const QModelIndex &);
98         /// update the display of BibTeX information
99         void updateInfo(BiblioInfo const & bi, QModelIndex const &);
100         /// enable/disable buttons
101         void setButtons();
102         /// fill the fields combo
103         void fillFields(BiblioInfo const & bi);
104         /// fill the entries combo
105         void fillEntries(BiblioInfo const & bi);
106         /// set the styles combo
107         void updateStyles(BiblioInfo const & bi);
108         /// set the formatting widgets
109         void updateFormatting(CitationStyle const & currentStyle);
110         ///
111         void updateControls(BiblioInfo const & bi);
112         /// Set the appropriate hinting text on the filter bar
113         void updateFilterHint();
114         ///
115         void init();
116         /// Clear selected keys
117         void clearSelection();
118
119         /// Set selected keys
120         void setSelectedKeys(QStringList const &);
121         /// Get selected keys
122         QStringList selectedKeys();
123         /// Set pre texts of qualified lists
124         void setPreTexts(std::vector<docstring> const & m);
125         /// Get pre texts of qualified lists
126         std::vector<docstring> getPreTexts();
127         /// Set post texts of qualified lists
128         void setPostTexts(std::vector<docstring> const & m);
129         /// Get post texts of qualified lists
130         std::vector<docstring> getPostTexts();
131
132         /// Find keys containing a string.
133         void findKey(
134                 BiblioInfo const & bi, //< optimize by passing this
135                 QString const & str, //< string expression
136                 bool only_keys, //< set to true if only keys shall be searched.
137                 docstring field, //<field to search, empty for all fields
138                 docstring entryType, //<entry type to display, empty for all
139                 bool case_sensitive, //< set to true for case sensitive search.
140                 bool reg_exp, //< set to true if \c str is a regular expression.
141                 bool reset = false //< whether to reset and search all keys
142                 );
143
144         /// List of example cite strings and their correlating lyx name
145         BiblioInfo::CiteStringMap citationStyles(BiblioInfo const & bi,
146                                                                 size_t max_size);
147
148         /// Set the Params variable for the Controller.
149         void applyParams(int const choice, bool const full, bool const force,
150                                           QString before, QString after);
151
152         ///
153         void filterByEntryType(BiblioInfo const & bi,
154                 std::vector<docstring> & keyVector, docstring entryType);
155
156         /// Search a given string within the passed keys.
157         /// \return the vector of matched keys.
158         std::vector<docstring> searchKeys(
159                 BiblioInfo const & bi, //< optimize by passing this
160                 std::vector<docstring> const & keys_to_search, //< Keys to search.
161                 bool only_keys, //< whether to search only the keys
162                 docstring const & search_expression, //< Search expression (regex possible)
163                 docstring field, //< field to search, empty for all fields
164                 bool case_sensitive = false, //< set to true is the search should be case sensitive
165                 bool regex = false //< \set to true if \c search_expression is a regex
166                 ); //
167
168         /// The BibTeX information available to the dialog
169         /// Calls to this method will lead to checks of modification times and
170         /// the like, so it should be avoided.
171         BiblioInfo const & bibInfo() const;
172
173         /// contains the search box
174         FancyLineEdit * filter_;
175
176         /// Regexp action
177         QAction * regexp_;
178         /// Case sensitive action
179         QAction * casesense_;
180         /// Search as you type action
181         QAction * instant_;
182
183         /// last used citation style
184         QString style_;
185         /// this is the last style chosen in the current dialog
186         QString last_chosen_style_;
187         ///
188         GuiSelectionManager * selectionManager;
189         /// available keys.
190         QStringListModel available_model_;
191         /// selected keys.
192         QStandardItemModel selected_model_;
193         /// All keys.
194         QStringList all_keys_;
195         /// Cited keys.
196         QStringList cited_keys_;
197         ///
198         InsetCommandParams params_;
199 };
200
201 } // namespace frontend
202 } // namespace lyx
203
204 #endif // GUICITATION_H