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 "QCitation.h"
15 #include "QCitationDialog.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 void toQStringList(QStringList & qlist, vector<string> const & v)
38 for (size_t i=0; i != v.size(); ++i) {
41 qlist.append(toqstr(v[i]));
45 void toVector(vector<string> & v, const QStringList & qlist)
49 for (size_t i=0; i != qlist.size(); ++i)
50 v.push_back(fromqstr(qlist[i]));
56 typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
59 QCitation::QCitation(Dialog & parent)
60 : base_class(parent, _("Citation"))
65 void QCitation::apply()
67 InsetCommandParams & params = controller().params();
68 dialog_->update(params);
70 params.setContents(fromqstr(selected_keys_.stringList().join("'")));
74 void QCitation::build_dialog()
76 dialog_.reset(new QCitationDialog(this));
80 void QCitation::update_contents()
84 // Make the list of all available bibliography keys
86 biblio::getKeys(controller().bibkeysInfo()));
87 available_keys_.setStringList(keys);
89 // Ditto for the keys cited in this inset
90 QString str = toqstr(controller().params().getContents());
92 keys = str.split(",");
93 selected_keys_.setStringList(keys);
96 dialog_->update(controller().params());
98 bc().valid(isValid());
101 void QCitation::hide()
106 bool QCitation::isValid()
108 return selected_keys_.rowCount() > 0;
111 QModelIndex QCitation::findKey(QString const & str, QModelIndex const & index) const
113 QStringList const avail = available_keys_.stringList();
114 int const pos = avail.indexOf(str, index.row());
117 return available_keys_.index(pos);
120 QModelIndex QCitation::findKey(QString const & str) const
122 QStringList const avail = available_keys_.stringList();
123 int const pos = avail.indexOf(str);
125 return QModelIndex();
126 return available_keys_.index(pos);
129 void QCitation::addKeys(QModelIndexList const & indexes)
131 // = selectionModel->selectedIndexes();
138 QStringList keys = selected_keys_.stringList();
140 foreach(index, indexes) {
141 if (keys.indexOf(index.data().toString()) == -1)
142 keys.append(index.data().toString());
145 selected_keys_.setStringList(keys);
150 void QCitation::deleteKeys(QModelIndexList const & indexes)
157 QStringList keys = selected_keys_.stringList();
159 foreach(index, indexes) {
160 int const pos = keys.indexOf(index.data().toString());
165 selected_keys_.setStringList(keys);
170 void QCitation::upKey(QModelIndexList const & indexes)
172 if (indexes.empty() || indexes.size() > 1)
175 int pos = indexes[0].row();
179 QStringList keys = selected_keys_.stringList();
180 keys.swap(pos, pos-1);
181 selected_keys_.setStringList(keys);
186 void QCitation::downKey(QModelIndexList const & indexes)
188 if (indexes.empty() || indexes.size() > 1)
191 int pos = indexes[0].row();
192 if (pos >= selected_keys_.rowCount() - 1)
195 QStringList keys = selected_keys_.stringList();
196 keys.swap(pos, pos+1);
197 selected_keys_.setStringList(keys);
207 } // namespace frontend