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