]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.h
5e07a24fa3c28cc9df779c9f6ec03bdd507cb6a8
[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_findLE_textChanged(const QString & text);
68         void on_fieldsCO_currentIndexChanged(int index);
69         void on_entriesCO_currentIndexChanged(int index);
70         void on_citationStyleCO_currentIndexChanged(int index);
71         void on_caseCB_stateChanged(int);
72         void on_regexCB_stateChanged(int);
73         void changed();
74         ///
75         void setCitedKeys();
76         /// performs a limited update, suitable for internal call
77         void updateDialog();
78         
79 private:
80         /// enable/disable buttons
81         void setButtons();
82         /// fill the styles combo
83         void fillStyles();
84         /// fill the fields combo
85         void fillFields();
86         /// fill the entries combo
87         void fillEntries();
88         /// set the styles combo
89         void updateStyle();
90         /// set the formatting widgets
91         void updateFormatting(CiteStyle currentStyle);
92         /// last used citation style
93         int style_;
94         
95         GuiSelectionManager * selectionManager;
96
97         ///
98         void init();
99         /// Available keys
100         QStringListModel * available() { return &available_model_; }
101         /// Selected keys
102         QStringListModel * selected() { return &selected_model_; }
103         /// Text before cite
104         QString textBefore();
105         /// Text after cite
106         QString textAfter();
107         /// Get key description
108         QString getKeyInfo(QString const &);
109         /// Clear selected keys
110         void clearSelection();
111         /// Return a list of available fields 
112         QStringList getFieldsAsQStringList();
113         /// Return a list of available fields 
114         QStringList getEntriesAsQStringList();
115         
116         /// Find keys containing a string.
117         void findKey(
118                 QString const & str, //< string expression
119                 bool only_keys, //< set to true if only keys shall be searched.
120                 docstring field, //<field to search, empty for all fields
121                 docstring entryType, //<entry type to display, empty for all
122                 bool case_sensitive, //< set to true for case sensitive search.
123                 bool reg_exp, //< set to true if \c str is a regular expression.
124                 bool reset = false //< whether to reset and search all keys
125                 );
126
127         /// List of example cite strings
128         QStringList citationStyles(int);
129
130         /// Set the Params variable for the Controller.
131         void apply(int const choice, bool const full, bool const force,
132                                           QString before, QString after);
133         ///
134         bool initialiseParams(std::string const & data);
135         /// clean-up on hide.
136         void clearParams();
137         /// clean-up on hide.
138         void dispatchParams();
139         ///
140         bool isBufferDependent() const { return true; }
141
142 private:
143         /// available keys.
144         QStringListModel available_model_;
145         /// selected keys.
146         QStringListModel selected_model_;
147         /// All keys.
148         QStringList all_keys_;
149         /// Cited keys.
150         QStringList cited_keys_;
151         ///
152         InsetCommandParams params_;
153
154         /** Disconnect from the inset when the Apply button is pressed.
155          *  Allows easy insertion of multiple citations.
156          */
157         bool disconnectOnApply() const { return true; }
158
159         /// \return the list of all available bibliography keys.
160         std::vector<docstring> availableKeys() const;
161         /// \return the list of all used BibTeX fields
162         std::vector<docstring> availableFields() const;
163         /// \return the list of all used BibTeX entry types
164         std::vector<docstring> availableEntries() const;
165         ///
166         void filterByEntryType(
167                 std::vector<docstring> & keyVector, docstring entryType);
168         ///
169         CiteEngine citeEngine() const;
170
171         /// \return information for this key.
172         docstring getInfo(docstring const & key) const;
173
174         /// Search a given string within the passed keys.
175         /// \return the vector of matched keys.
176         std::vector<docstring> searchKeys(
177                 std::vector<docstring> const & keys_to_search, //< Keys to search.
178                 bool only_keys, //< whether to search only the keys
179                 docstring const & search_expression, //< Search expression (regex possible)
180                 docstring field, //< field to search, empty for all fields
181                 bool case_sensitive = false, //< set to true is the search should be case sensitive
182                 bool regex = false //< \set to true if \c search_expression is a regex
183                 ); //
184
185 private:
186         /// The BibTeX information available to the dialog
187         BiblioInfo bibkeysInfo_;
188 };
189
190 } // namespace frontend
191 } // namespace lyx
192
193 #endif // GUICITATION_H