]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QCitation.C
remove qPixmapFromMimeSource. This caused the inclusion of Qt3 support headers which...
[lyx.git] / src / frontends / qt4 / QCitation.C
1 /**
2  * \file QCitation.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Kalle Dalheimer
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlCitation.h"
15 #include "QCitation.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18
19 #include "bufferparams.h"
20
21 #include "controllers/ButtonController.h"
22 #include "controllers/ControlCitation.h"
23
24 #include "support/lstrings.h"
25
26 #include <vector>
27 #include <string>
28
29 using std::vector;
30 using std::string;
31
32
33 QStringList toQStringList(vector<string> const & v)
34 {
35         QStringList qlist;
36
37         for (size_t i=0; i != v.size(); ++i) {
38                 if (v[i].empty())
39                         continue;
40                 qlist.append(toqstr(v[i]));
41         }
42         return qlist;
43 }
44
45
46 namespace lyx {
47 namespace frontend {
48
49
50 QCitation::QCitation(Dialog & parent)
51         : ControlCitation(parent)
52 {
53 }
54
55
56 void QCitation::apply(int const choice, bool const full, bool const force,
57                                           QString before, QString after)
58 {
59         if (!isValid())
60                 return;
61
62         vector<biblio::CiteStyle> const & styles =
63                 ControlCitation::getCiteStyles();
64
65         string const command =
66                 biblio::CitationStyle(styles[choice], full, force)
67                 .asLatexStr();
68
69         params().setCmdName(command);
70         params().setContents(fromqstr(selected_keys_.stringList().join(",")));
71         params().setSecOptions(fromqstr(before));
72         params().setOptions(fromqstr(after));
73         dispatchParams();
74 }
75
76
77 QString QCitation::textBefore()
78 {
79         return toqstr(params().getSecOptions());
80 }
81
82
83 QString QCitation::textAfter()
84 {
85         return toqstr(params().getOptions());
86 }
87
88
89 void QCitation::updateModel()
90 {
91         // Make the list of all available bibliography keys
92         QStringList keys = toQStringList(biblio::getKeys(bibkeysInfo()));
93         available_keys_.setStringList(keys);
94
95         // Ditto for the keys cited in this inset
96         QString str = toqstr(params().getContents());
97         if (!str.isEmpty()) {
98                 keys = str.split(",");
99                 selected_keys_.setStringList(keys);
100         }
101 }
102
103
104 bool QCitation::isValid()
105 {
106         return selected_keys_.rowCount() > 0;
107 }
108
109
110 void QCitation::findKey(QString const & str)
111 {
112         QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);
113         found_keys_.setStringList(sl);
114 }
115
116
117 void QCitation::addKey(QModelIndex const & index)
118 {
119         QStringList keys = selected_keys_.stringList();
120         keys.append(index.data().toString());
121         selected_keys_.setStringList(keys);
122 }
123
124
125 void QCitation::deleteKey(QModelIndex const & index)
126 {
127         QStringList keys = selected_keys_.stringList();
128         keys.removeAt(index.row());
129         selected_keys_.setStringList(keys);
130 }
131
132
133 void QCitation::upKey(QModelIndex const & index)
134 {
135         QStringList keys = selected_keys_.stringList();
136         int pos = index.row();
137         keys.swap(pos, pos - 1);
138         selected_keys_.setStringList(keys);
139 }
140
141
142 void QCitation::downKey(QModelIndex const & index)
143 {
144         QStringList keys = selected_keys_.stringList();
145         int pos = index.row();
146         keys.swap(pos, pos + 1);
147         selected_keys_.setStringList(keys);
148 }
149
150
151 QStringList QCitation::citationStyles(int sel)
152 {
153         string key = fromqstr(selected_keys_.stringList()[sel]);
154         return toQStringList(getCiteStrings(key));
155 }
156
157
158 QString QCitation::getKeyInfo(QString const & sel)
159 {
160         if (!bibkeysInfo().empty())
161                 return toqstr(biblio::getInfo(bibkeysInfo(), fromqstr(sel) ));
162
163         return QString();
164 }
165
166
167 } // namespace frontend
168 } // namespace lyx