]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiCitation.h
8746a1aa65f004f829280a6b06d4982b40c55151
[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 "DialogView.h"
19 #include "ui_CitationUi.h"
20
21 #include "insets/InsetCommandParams.h"
22
23 #include "Citation.h"
24
25 #include <QStringList>
26 #include <QStringListModel>
27
28 namespace lyx {
29
30 class BiblioInfo;
31
32 namespace frontend {
33
34 class GuiSelectionManager;
35
36 class GuiCitation : public DialogView, public Ui::CitationUi
37 {
38         Q_OBJECT
39
40 public:
41         ///
42         GuiCitation(GuiView & lv);
43         ///
44         ~GuiCitation();
45         /// We use the main document's buffer() so to catch the citations
46         /// defined there, also while using the dialog from the Adv F&R.
47         Buffer const & buffer() const;
48
49 private Q_SLOTS:
50         void on_okPB_clicked();
51         void on_cancelPB_clicked();
52         void on_restorePB_clicked();
53         void on_applyPB_clicked();
54         void on_searchPB_clicked();
55         void on_findLE_textChanged(const QString & text);
56         void on_fieldsCO_currentIndexChanged(int index);
57         void on_entriesCO_currentIndexChanged(int index);
58         void on_citationStyleCO_currentIndexChanged(int index);
59         void on_caseCB_stateChanged(int);
60         void on_regexCB_stateChanged(int);
61         void on_asTypeCB_stateChanged(int);
62         void changed();
63         ///
64         void setCitedKeys();
65         /// performs a limited update, suitable for internal call
66         void updateControls();
67         
68
69 private:
70         /// Dialog inherited methods
71         //@{
72         void applyView();
73         void updateView() {}
74         bool initialiseParams(std::string const & data);
75         void clearParams();
76         void dispatchParams();
77         bool isBufferDependent() const { return true; }
78         void saveSession() const;
79         void restoreSession();
80         /** Disconnect from the inset when the Apply button is pressed.
81          *  Allows easy insertion of multiple citations.
82          */
83         bool disconnectOnApply() const { return true; }
84         //@}
85
86         ///
87         void showEvent(QShowEvent * e);
88         ///
89         void closeEvent(QCloseEvent * e);
90         /// prepares a call to GuiCitation::searchKeys when we
91         /// are ready to search the BibTeX entries
92         void findText(QString const & text, bool reset = false);
93         /// check whether key is already selected
94         bool isSelected(const QModelIndex &);
95         /// update the display of BibTeX information
96         void updateInfo(BiblioInfo const & bi, QModelIndex const &);
97         /// enable/disable buttons
98         void setButtons();
99         /// fill the styles combo
100         void fillStyles(BiblioInfo const & bi);
101         /// fill the fields combo
102         void fillFields(BiblioInfo const & bi);
103         /// fill the entries combo
104         void fillEntries(BiblioInfo const & bi);
105         /// set the styles combo
106         void updateStyle();
107         /// set the formatting widgets
108         void updateFormatting(CiteStyle currentStyle);
109         ///
110         void updateControls(BiblioInfo const & bi);
111         ///
112         void init();
113         /// Clear selected keys
114         void clearSelection();
115         
116         /// Find keys containing a string.
117         void findKey(
118                 BiblioInfo const & bi, //< optimize by passing this
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(BiblioInfo const & bi, 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         ///
136         void filterByEntryType(BiblioInfo const & bi,
137                 std::vector<docstring> & keyVector, docstring entryType);
138         ///
139         CiteEngine citeEngine() const;
140
141         /// Search a given string within the passed keys.
142         /// \return the vector of matched keys.
143         std::vector<docstring> searchKeys(
144                 BiblioInfo const & bi, //< optimize by passing this
145                 std::vector<docstring> const & keys_to_search, //< Keys to search.
146                 bool only_keys, //< whether to search only the keys
147                 docstring const & search_expression, //< Search expression (regex possible)
148                 docstring field, //< field to search, empty for all fields
149                 bool case_sensitive = false, //< set to true is the search should be case sensitive
150                 bool regex = false //< \set to true if \c search_expression is a regex
151                 ); //
152
153         /// The BibTeX information available to the dialog
154         /// Calls to this method will lead to checks of modification times and 
155         /// the like, so it should be avoided.
156         BiblioInfo const & bibInfo() const;
157
158         /// last used citation style
159         int style_;
160         ///
161         GuiSelectionManager * selectionManager;
162         /// available keys.
163         QStringListModel available_model_;
164         /// selected keys.
165         QStringListModel selected_model_;
166         /// All keys.
167         QStringList all_keys_;
168         /// Cited keys.
169         QStringList cited_keys_;
170         ///
171         InsetCommandParams params_;
172 };
173
174 } // namespace frontend
175 } // namespace lyx
176
177 #endif // GUICITATION_H