2006-03-05 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* \file QCitation.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Kalle Dalheimer
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QCitation.h"
|
|
|
|
#include "QCitationDialog.h"
|
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include "bufferparams.h"
|
|
|
|
|
|
|
|
#include "controllers/ButtonController.h"
|
|
|
|
#include "controllers/ControlCitation.h"
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::vector;
|
2006-03-25 21:26:09 +00:00
|
|
|
using std::string;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void toQStringList(QStringList & qlist, vector<string> const & v)
|
|
|
|
{
|
|
|
|
qlist.clear();
|
|
|
|
for (size_t i=0; i != v.size(); ++i) {
|
|
|
|
if (v[i].empty())
|
|
|
|
continue;
|
|
|
|
qlist.append(toqstr(v[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void toVector(vector<string> & v, const QStringList & qlist)
|
|
|
|
{
|
|
|
|
v.clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
for (size_t i=0; i != qlist.size(); ++i)
|
|
|
|
v.push_back(fromqstr(qlist[i]));
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
namespace lyx {
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QCitation::QCitation(Dialog & parent)
|
|
|
|
: base_class(parent, _("Citation"))
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
void QCitation::apply()
|
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
InsetCommandParams & params = controller().params();
|
2006-03-26 18:35:15 +00:00
|
|
|
dialog_->apply(params);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
params.setContents(fromqstr(selected_keys_.stringList().join("'")));
|
2006-03-26 18:35:15 +00:00
|
|
|
/*
|
|
|
|
if (dialog().controller().isBufferDependent()) {
|
|
|
|
if (!dialog().kernel().isBufferAvailable() ||
|
|
|
|
dialog().kernel().isBufferReadonly())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog().view().apply();
|
|
|
|
dialog().controller().dispatchParams();
|
|
|
|
|
|
|
|
if (dialog().controller().disconnectOnApply()) {
|
|
|
|
dialog().kernel().disconnect(name());
|
|
|
|
dialog().controller().initialiseParams(string());
|
|
|
|
dialog().view().update();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// dialog().ApplyButton();
|
|
|
|
// dialog().apply();
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitation::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QCitationDialog(this));
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void QCitation::update_contents()
|
|
|
|
{
|
|
|
|
QStringList keys;
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
// Make the list of all available bibliography keys
|
|
|
|
toQStringList(keys,
|
|
|
|
biblio::getKeys(controller().bibkeysInfo()));
|
|
|
|
available_keys_.setStringList(keys);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
// Ditto for the keys cited in this inset
|
|
|
|
QString str = toqstr(controller().params().getContents());
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
keys = str.split(",");
|
|
|
|
selected_keys_.setStringList(keys);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
dialog_->update(controller().params());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
bc().valid(isValid());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QCitation::hide()
|
|
|
|
{
|
|
|
|
QDialogView::hide();
|
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
bool QCitation::isValid()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
return selected_keys_.rowCount() > 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QModelIndex QCitation::findKey(QString const & str, QModelIndex const & index) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList const avail = available_keys_.stringList();
|
|
|
|
int const pos = avail.indexOf(str, index.row());
|
|
|
|
if (pos == -1)
|
|
|
|
return index;
|
|
|
|
return available_keys_.index(pos);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QModelIndex QCitation::findKey(QString const & str) const
|
|
|
|
{
|
2006-03-26 18:35:15 +00:00
|
|
|
cout << "Find text " << fromqstr(str) << endl;
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList const avail = available_keys_.stringList();
|
2006-03-26 18:35:15 +00:00
|
|
|
QRegExp reg_exp(str);
|
|
|
|
|
|
|
|
int const pos = avail.indexOf(reg_exp);
|
2006-03-25 21:26:09 +00:00
|
|
|
if (pos == -1)
|
|
|
|
return QModelIndex();
|
2006-03-26 18:35:15 +00:00
|
|
|
|
|
|
|
cout << "found key " << fromqstr(avail[pos]) << " at pos " << pos << endl;
|
2006-03-25 21:26:09 +00:00
|
|
|
return available_keys_.index(pos);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void QCitation::addKeys(QModelIndexList const & indexes)
|
|
|
|
{
|
|
|
|
// = selectionModel->selectedIndexes();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QModelIndex index;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
if (indexes.empty())
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
foreach(index, indexes) {
|
|
|
|
if (keys.indexOf(index.data().toString()) == -1)
|
|
|
|
keys.append(index.data().toString());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void QCitation::deleteKeys(QModelIndexList const & indexes)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
QModelIndex index;
|
|
|
|
|
|
|
|
if (indexes.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
foreach(index, indexes) {
|
|
|
|
int const pos = keys.indexOf(index.data().toString());
|
|
|
|
if (pos != -1)
|
|
|
|
keys.removeAt(pos);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
changed();
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void QCitation::upKey(QModelIndexList const & indexes)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
if (indexes.empty() || indexes.size() > 1)
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
int pos = indexes[0].row();
|
|
|
|
if (pos < 1)
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList keys = selected_keys_.stringList();
|
|
|
|
keys.swap(pos, pos-1);
|
|
|
|
selected_keys_.setStringList(keys);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
changed();
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
void QCitation::downKey(QModelIndexList const & indexes)
|
|
|
|
{
|
|
|
|
if (indexes.empty() || indexes.size() > 1)
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
int pos = indexes[0].row();
|
|
|
|
if (pos >= selected_keys_.rowCount() - 1)
|
|
|
|
return;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList keys = selected_keys_.stringList();
|
|
|
|
keys.swap(pos, pos+1);
|
|
|
|
selected_keys_.setStringList(keys);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
changed();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|