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