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>
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
#include "ControlCitation.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QCitation.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>
|
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-04-11 08:26:43 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
static QStringList toQStringList(vector<string> const & v)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-04-11 08:26:43 +00:00
|
|
|
QStringList qlist;
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
for (size_t i=0; i != v.size(); ++i) {
|
|
|
|
if (v[i].empty())
|
|
|
|
continue;
|
2006-10-21 00:16:43 +00:00
|
|
|
qlist.append(lyx::toqstr(v[i]));
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-04-11 08:26:43 +00:00
|
|
|
return qlist;
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
namespace lyx {
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2006-03-25 21:26:09 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
QCitation::QCitation(Dialog & parent)
|
2006-04-11 08:26:43 +00:00
|
|
|
: ControlCitation(parent)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
void QCitation::apply(int const choice, bool const full, bool const force,
|
|
|
|
QString before, QString after)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-06-28 08:28:16 +00:00
|
|
|
if (!isValid())
|
|
|
|
return;
|
2006-04-11 08:26:43 +00:00
|
|
|
|
|
|
|
vector<biblio::CiteStyle> const & styles =
|
|
|
|
ControlCitation::getCiteStyles();
|
|
|
|
|
|
|
|
string const command =
|
|
|
|
biblio::CitationStyle(styles[choice], full, force)
|
|
|
|
.asLatexStr();
|
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
params().setCmdName(command);
|
2006-04-11 08:26:43 +00:00
|
|
|
params().setContents(fromqstr(selected_keys_.stringList().join(",")));
|
|
|
|
params().setSecOptions(fromqstr(before));
|
|
|
|
params().setOptions(fromqstr(after));
|
|
|
|
dispatchParams();
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
QString QCitation::textBefore()
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-04-11 08:26:43 +00:00
|
|
|
return toqstr(params().getSecOptions());
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
QString QCitation::textAfter()
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-04-11 08:26:43 +00:00
|
|
|
return toqstr(params().getOptions());
|
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
|
|
|
void QCitation::updateModel()
|
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
// Make the list of all available bibliography keys
|
2006-04-11 08:26:43 +00:00
|
|
|
QStringList keys = toQStringList(biblio::getKeys(bibkeysInfo()));
|
2006-03-25 21:26:09 +00:00
|
|
|
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
|
2006-04-11 08:26:43 +00:00
|
|
|
QString str = toqstr(params().getContents());
|
2006-03-25 21:26:09 +00:00
|
|
|
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
|
|
|
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-04-11 08:26:43 +00:00
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
void QCitation::findKey(QString const & str)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-06-28 08:28:16 +00:00
|
|
|
QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);
|
|
|
|
found_keys_.setStringList(sl);
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
void QCitation::addKey(QModelIndex const & index)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-06-28 08:28:16 +00:00
|
|
|
keys.append(index.data().toString());
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
void QCitation::deleteKey(QModelIndex const & index)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-06-28 08:28:16 +00:00
|
|
|
keys.removeAt(index.row());
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
void QCitation::upKey(QModelIndex const & index)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-06-28 08:28:16 +00:00
|
|
|
int pos = index.row();
|
|
|
|
keys.swap(pos, pos - 1);
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
void QCitation::downKey(QModelIndex const & index)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
|
|
|
QStringList keys = selected_keys_.stringList();
|
2006-06-28 08:28:16 +00:00
|
|
|
int pos = index.row();
|
|
|
|
keys.swap(pos, pos + 1);
|
2006-03-25 21:26:09 +00:00
|
|
|
selected_keys_.setStringList(keys);
|
2006-04-11 08:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList QCitation::citationStyles(int sel)
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
string const key = fromqstr(selected_keys_.stringList()[sel]);
|
2006-04-11 08:26:43 +00:00
|
|
|
return toQStringList(getCiteStrings(key));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
|
|
|
|
QString QCitation::getKeyInfo(QString const & sel)
|
|
|
|
{
|
|
|
|
if (!bibkeysInfo().empty())
|
|
|
|
return toqstr(biblio::getInfo(bibkeysInfo(), fromqstr(sel) ));
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|