]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.h
fix memory leaks
[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 #include "support/docstring.h"
22 #include "BiblioInfo.h"
23
24 #include <QKeyEvent>
25 #include <QStringList>
26 #include <QStringListModel>
27
28 namespace lyx {
29 namespace frontend {
30
31 class GuiCitation : public GuiCommand, public Ui::CitationUi
32 {
33         Q_OBJECT
34
35 public:
36         ///
37         GuiCitation(GuiView & lv);
38
39         ///
40         void applyView();
41         /// Hide the dialog from sight
42         void hideView();
43         /// Create the dialog if necessary, update it and display it.
44         void showView();
45         /// \return true if the dialog is visible.
46         bool isVisibleView() const;
47
48 public Q_SLOTS:
49         /// Update the display of the dialog whilst it is still visible.
50         void updateView();
51
52 private:
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_findLE_textChanged(const QString & text);
70         void on_fieldsCO_currentIndexChanged(int index);
71         void on_entriesCO_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         /// last used citation style
92         int style_;
93         
94         GuiSelectionManager * selectionManager;
95
96         ///
97         void init();
98         /// Available keys
99         QStringListModel * available() { return &available_model_; }
100         /// Selected keys
101         QStringListModel * selected() { return &selected_model_; }
102         /// Text before cite
103         QString textBefore();
104         /// Text after cite
105         QString textAfter();
106         /// Get key description
107         QString getKeyInfo(QString const &);
108         /// Clear selected keys
109         void clearSelection();
110         /// Return a list of available fields 
111         QStringList getFieldsAsQStringList();
112         /// Return a list of available fields 
113         QStringList getEntriesAsQStringList();
114         
115         /// Find keys containing a string.
116         void findKey(
117                 QString const & str, //< string expression
118                 bool only_keys, //< set to true if only keys shall be searched.
119                 docstring field, //<field to search, empty for all fields
120                 docstring entryType, //<entry type to display, empty for all
121                 bool case_sensitive, //< set to true for case sensitive search.
122                 bool reg_exp, //< set to true if \c str is a regular expression.
123                 bool reset = false //< whether to reset and search all keys
124                 );
125
126         /// List of example cite strings
127         QStringList citationStyles(int);
128
129         /// Set the Params variable for the Controller.
130         void apply(int const choice, bool const full, bool const force,
131                                           QString before, QString after);
132
133 private:
134         /// available keys.
135         QStringListModel available_model_;
136         /// selected keys.
137         QStringListModel selected_model_;
138         /// All keys.
139         QStringList all_keys_;
140         /// Cited keys.
141         QStringList cited_keys_;
142
143         ///
144         bool initialiseParams(std::string const & data);
145
146         /// clean-up on hide.
147         void clearParams();
148
149         /** Disconnect from the inset when the Apply button is pressed.
150          *  Allows easy insertion of multiple citations.
151          */
152         bool disconnectOnApply() const { return true; }
153
154         /// \return the list of all available bibliography keys.
155         std::vector<docstring> const availableKeys() const;
156         /// \return the list of all used BibTeX fields
157         std::vector<docstring> const availableFields() const;
158         /// \return the list of all used BibTeX entry types
159         std::vector<docstring> const availableEntries() const;
160         ///
161         void filterByEntryType(
162                 std::vector<docstring> & keyVector, docstring entryType);
163         ///
164         biblio::CiteEngine getEngine() const;
165
166         /// \return information for this key.
167         docstring getInfo(docstring const & key) const;
168
169         /// Search a given string within the passed keys.
170         /// \return the vector of matched keys.
171         std::vector<docstring> searchKeys(
172                 std::vector<docstring> const & keys_to_search, //< Keys to search.
173                 bool only_keys, //< whether to search only the keys
174                 docstring const & search_expression, //< Search expression (regex possible)
175                 docstring field, //< field to search, empty for all fields
176                 bool case_sensitive = false, //< set to true is the search should be case sensitive
177                 bool regex = false //< \set to true if \c search_expression is a regex
178                 ); //
179
180 private:
181         /// The BibTeX information available to the dialog
182         BiblioInfo bibkeysInfo_;
183 };
184
185 } // namespace frontend
186 } // namespace lyx
187
188 #endif // GUICITATION_H