3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Kalle Dalheimer
9 * Full author contact details are available in file CREDITS.
14 #include "ControlCitation.h"
15 #include "QCitation.h"
17 #include "qt_helpers.h"
19 #include "bufferparams.h"
21 #include "controllers/ButtonController.h"
22 #include "controllers/ControlCitation.h"
24 #include "support/lstrings.h"
35 template<typename String> static QStringList toQStringList(vector<String> const & v)
39 for (size_t i=0; i != v.size(); ++i) {
42 qlist.append(lyx::toqstr(v[i]));
54 QCitation::QCitation(Dialog & parent)
55 : ControlCitation(parent)
60 void QCitation::apply(int const choice, bool const full, bool const force,
61 QString before, QString after)
63 if (selected_keys_.rowCount() == 0)
66 vector<biblio::CiteStyle> const & styles =
67 ControlCitation::getCiteStyles();
69 string const command =
70 biblio::CitationStyle(styles[choice], full, force)
73 params().setCmdName(command);
74 params()["key"] = qstring_to_ucs4(selected_keys_.stringList().join(","));
75 params()["before"] = qstring_to_ucs4(before);
76 params()["after"] = qstring_to_ucs4(after);
81 void QCitation::clearSelection()
83 selected_keys_.setStringList(QStringList());
87 QString QCitation::textBefore()
89 return toqstr(params()["before"]);
93 QString QCitation::textAfter()
95 return toqstr(params()["after"]);
99 void QCitation::updateModel()
101 // Make the list of all available bibliography keys
102 QStringList keys = toQStringList(biblio::getKeys(bibkeysInfo()));
103 available_keys_.setStringList(keys);
105 // Ditto for the keys cited in this inset
106 QString str = toqstr(params()["key"]);
107 if (!str.isEmpty()) {
108 keys = str.split(",");
109 selected_keys_.setStringList(keys);
114 void QCitation::findKey(QString const & str)
116 QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);
117 found_keys_.setStringList(sl);
121 void QCitation::addKey(QModelIndex const & index)
123 QStringList keys = selected_keys_.stringList();
124 keys.append(index.data().toString());
125 selected_keys_.setStringList(keys);
129 void QCitation::deleteKey(QModelIndex const & index)
131 QStringList keys = selected_keys_.stringList();
132 keys.removeAt(index.row());
133 selected_keys_.setStringList(keys);
137 void QCitation::upKey(QModelIndex const & index)
139 QStringList keys = selected_keys_.stringList();
140 int pos = index.row();
141 keys.swap(pos, pos - 1);
142 selected_keys_.setStringList(keys);
146 void QCitation::downKey(QModelIndex const & index)
148 QStringList keys = selected_keys_.stringList();
149 int pos = index.row();
150 keys.swap(pos, pos + 1);
151 selected_keys_.setStringList(keys);
155 QStringList QCitation::citationStyles(int sel)
157 string const key = fromqstr(selected_keys_.stringList()[sel]);
158 return toQStringList(getCiteStrings(key));
162 QString QCitation::getKeyInfo(QString const & sel)
164 if (!bibkeysInfo().empty())
165 return toqstr(biblio::getInfo(bibkeysInfo(), fromqstr(sel) ));
171 } // namespace frontend