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