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