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