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"
33 QStringList toQStringList(vector<string> const & v)
37 for (size_t i=0; i != v.size(); ++i) {
40 qlist.append(toqstr(v[i]));
50 QCitation::QCitation(Dialog & parent)
51 : ControlCitation(parent)
56 void QCitation::apply(int const choice, bool const full, bool const force,
57 QString before, QString after)
62 vector<biblio::CiteStyle> const & styles =
63 ControlCitation::getCiteStyles();
65 string const command =
66 biblio::CitationStyle(styles[choice], full, force)
69 params().setCmdName(command);
70 params().setContents(fromqstr(selected_keys_.stringList().join(",")));
71 params().setSecOptions(fromqstr(before));
72 params().setOptions(fromqstr(after));
77 QString QCitation::textBefore()
79 return toqstr(params().getSecOptions());
83 QString QCitation::textAfter()
85 return toqstr(params().getOptions());
89 void QCitation::updateModel()
91 // Make the list of all available bibliography keys
92 QStringList keys = toQStringList(biblio::getKeys(bibkeysInfo()));
93 available_keys_.setStringList(keys);
95 // Ditto for the keys cited in this inset
96 QString str = toqstr(params().getContents());
98 keys = str.split(",");
99 selected_keys_.setStringList(keys);
104 bool QCitation::isValid()
106 return selected_keys_.rowCount() > 0;
110 void QCitation::findKey(QString const & str)
112 QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);
113 found_keys_.setStringList(sl);
117 void QCitation::addKey(QModelIndex const & index)
119 QStringList keys = selected_keys_.stringList();
120 keys.append(index.data().toString());
121 selected_keys_.setStringList(keys);
125 void QCitation::deleteKey(QModelIndex const & index)
127 QStringList keys = selected_keys_.stringList();
128 keys.removeAt(index.row());
129 selected_keys_.setStringList(keys);
133 void QCitation::upKey(QModelIndex const & index)
135 QStringList keys = selected_keys_.stringList();
136 int pos = index.row();
137 keys.swap(pos, pos - 1);
138 selected_keys_.setStringList(keys);
142 void QCitation::downKey(QModelIndex const & index)
144 QStringList keys = selected_keys_.stringList();
145 int pos = index.row();
146 keys.swap(pos, pos + 1);
147 selected_keys_.setStringList(keys);
151 QStringList QCitation::citationStyles(int sel)
153 string key = fromqstr(selected_keys_.stringList()[sel]);
154 return toQStringList(getCiteStrings(key));
158 QString QCitation::getKeyInfo(QString const & sel)
160 if (!bibkeysInfo().empty())
161 return toqstr(biblio::getInfo(bibkeysInfo(), fromqstr(sel) ));
167 } // namespace frontend