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