]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.h
52b6b315d6ac2a1ae6803a3ea5ed6fdc788c66f1
[lyx.git] / src / frontends / qt4 / 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
21 #include "insets/InsetCommandParams.h"
22
23 #include "Citation.h"
24
25 #include <QStringList>
26 #include <QStringListModel>
27
28 namespace lyx {
29
30 class BiblioInfo;
31
32 namespace frontend {
33
34 class GuiSelectionManager;
35
36 class GuiCitation : public DialogView, public Ui::CitationUi
37 {
38         Q_OBJECT
39
40 public:
41         ///
42         GuiCitation(GuiView & lv);
43         ///
44         ~GuiCitation();
45         ///
46         void applyView();
47
48         void updateView() {}
49
50 private:
51         ///
52         void showEvent(QShowEvent * e);
53         ///
54         void closeEvent(QCloseEvent * e);
55         /// prepares a call to GuiCitation::searchKeys when we
56         /// are ready to search the BibTeX entries
57         void findText(QString const & text, bool reset = false);
58         /// check whether key is already selected
59         bool isSelected(const QModelIndex &);
60         /// update the display of BibTeX information
61         void updateInfo(QModelIndex const &);
62
63 private Q_SLOTS:
64         void cleanUp();
65         void on_okPB_clicked();
66         void on_cancelPB_clicked();
67         void on_restorePB_clicked();
68         void on_applyPB_clicked();
69         void on_searchPB_clicked();
70         void on_findLE_textChanged(const QString & text);
71         void on_fieldsCO_currentIndexChanged(int index);
72         void on_entriesCO_currentIndexChanged(int index);
73         void on_citationStyleCO_currentIndexChanged(int index);
74         void on_caseCB_stateChanged(int);
75         void on_regexCB_stateChanged(int);
76         void on_asTypeCB_stateChanged(int);
77         void changed();
78         ///
79         void setCitedKeys();
80         /// performs a limited update, suitable for internal call
81         void updateControls();
82         
83 private:
84         /// enable/disable buttons
85         void setButtons();
86         /// fill the styles combo
87         void fillStyles();
88         /// fill the fields combo
89         void fillFields();
90         /// fill the entries combo
91         void fillEntries();
92         /// set the styles combo
93         void updateStyle();
94         /// set the formatting widgets
95         void updateFormatting(CiteStyle currentStyle);
96         /// last used citation style
97         int style_;
98         
99         GuiSelectionManager * selectionManager;
100
101         ///
102         void init();
103         /// Available keys
104         QStringListModel * available() { return &available_model_; }
105         /// Selected keys
106         QStringListModel * selected() { return &selected_model_; }
107         /// Text before cite
108         QString textBefore();
109         /// Text after cite
110         QString textAfter();
111         /// Get key description
112         QString getKeyInfo(QString const &);
113         /// Clear selected keys
114         void clearSelection();
115         /// Return a list of available fields 
116         QStringList getFieldsAsQStringList();
117         /// Return a list of available fields 
118         QStringList getEntriesAsQStringList();
119         
120         /// Find keys containing a string.
121         void findKey(
122                 QString const & str, //< string expression
123                 bool only_keys, //< set to true if only keys shall be searched.
124                 docstring field, //<field to search, empty for all fields
125                 docstring entryType, //<entry type to display, empty for all
126                 bool case_sensitive, //< set to true for case sensitive search.
127                 bool reg_exp, //< set to true if \c str is a regular expression.
128                 bool reset = false //< whether to reset and search all keys
129                 );
130
131         /// List of example cite strings
132         QStringList citationStyles(int);
133
134         /// Set the Params variable for the Controller.
135         void apply(int const choice, bool const full, bool const force,
136                                           QString before, QString after);
137         ///
138         bool initialiseParams(std::string const & data);
139         /// clean-up on hide.
140         void clearParams();
141         /// clean-up on hide.
142         void dispatchParams();
143         ///
144         bool isBufferDependent() const { return true; }
145
146 private:
147         /// available keys.
148         QStringListModel available_model_;
149         /// selected keys.
150         QStringListModel selected_model_;
151         /// All keys.
152         QStringList all_keys_;
153         /// Cited keys.
154         QStringList cited_keys_;
155         ///
156         InsetCommandParams params_;
157
158         /** Disconnect from the inset when the Apply button is pressed.
159          *  Allows easy insertion of multiple citations.
160          */
161         bool disconnectOnApply() const { return true; }
162
163         /// \return the list of all available bibliography keys.
164         std::vector<docstring> availableKeys() const;
165         /// \return the list of all used BibTeX fields
166         std::vector<docstring> availableFields() const;
167         /// \return the list of all used BibTeX entry types
168         std::vector<docstring> availableEntries() const;
169         ///
170         void filterByEntryType(
171                 std::vector<docstring> & keyVector, docstring entryType);
172         ///
173         CiteEngine citeEngine() const;
174
175         /// \return information for this key.
176         docstring getInfo(docstring const & key) const;
177
178         /// Search a given string within the passed keys.
179         /// \return the vector of matched keys.
180         std::vector<docstring> searchKeys(
181                 std::vector<docstring> const & keys_to_search, //< Keys to search.
182                 bool only_keys, //< whether to search only the keys
183                 docstring const & search_expression, //< Search expression (regex possible)
184                 docstring field, //< field to search, empty for all fields
185                 bool case_sensitive = false, //< set to true is the search should be case sensitive
186                 bool regex = false //< \set to true if \c search_expression is a regex
187                 ); //
188
189 private:
190         /// The BibTeX information available to the dialog
191         BiblioInfo const & bibInfo() const;
192 };
193
194 } // namespace frontend
195 } // namespace lyx
196
197 #endif // GUICITATION_H