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