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