This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file QCitation.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Kalle Dalheimer
|
2007-03-25 01:32:12 +00:00
|
|
|
* \author Abdelrazak Younes
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
* \author Richard Heck (adapted to QSelectionManager)
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "QCitation.h"
|
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2007-08-20 16:30:02 +00:00
|
|
|
#include "support/docstring.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
#include "debug.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
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
template<typename String> static QStringList to_qstring_list(vector<String> const & v)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-04-11 08:26:43 +00:00
|
|
|
QStringList qlist;
|
|
|
|
|
2007-04-25 16:39:21 +00:00
|
|
|
for (size_t i = 0; i != v.size(); ++i) {
|
2006-03-25 21:26:09 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
static vector<lyx::docstring> const to_docstring_vector(QStringList const & qlist)
|
2007-03-25 01:32:12 +00:00
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
vector<lyx::docstring> v;
|
2007-03-25 10:32:22 +00:00
|
|
|
for (int i = 0; i != qlist.size(); ++i) {
|
2007-03-25 01:32:12 +00:00
|
|
|
if (qlist[i].isEmpty())
|
|
|
|
continue;
|
2007-08-20 16:30:02 +00:00
|
|
|
v.push_back(lyx::qstring_to_ucs4(qlist[i]));
|
2007-03-25 01:32:12 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
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,
|
2007-05-28 22:27:45 +00:00
|
|
|
QString before, QString after)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-25 01:32:12 +00:00
|
|
|
if (cited_keys_.isEmpty())
|
2006-06-28 08:28:16 +00:00
|
|
|
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);
|
2007-03-25 01:32:12 +00:00
|
|
|
params()["key"] = qstring_to_ucs4(cited_keys_.join(","));
|
2006-12-10 10:31:42 +00:00
|
|
|
params()["before"] = qstring_to_ucs4(before);
|
|
|
|
params()["after"] = qstring_to_ucs4(after);
|
2006-04-11 08:26:43 +00:00
|
|
|
dispatchParams();
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-15 09:58:44 +00:00
|
|
|
void QCitation::clearSelection()
|
|
|
|
{
|
2007-03-25 01:32:12 +00:00
|
|
|
cited_keys_.clear();
|
|
|
|
selected_model_.setStringList(cited_keys_);
|
2006-12-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
QString QCitation::textBefore()
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2006-12-10 10:31:42 +00:00
|
|
|
return toqstr(params()["before"]);
|
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-12-10 10:31:42 +00:00
|
|
|
return toqstr(params()["after"]);
|
2006-04-11 08:26:43 +00:00
|
|
|
}
|
2006-04-05 23:56:29 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
bool QCitation::initialiseParams(std::string const & data)
|
|
|
|
{
|
|
|
|
if (!ControlCitation::initialiseParams(data))
|
|
|
|
return false;
|
|
|
|
init();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitation::init()
|
2006-04-11 08:26:43 +00:00
|
|
|
{
|
2006-03-25 21:26:09 +00:00
|
|
|
// Make the list of all available bibliography keys
|
2007-03-25 01:32:12 +00:00
|
|
|
all_keys_ = to_qstring_list(availableKeys());
|
|
|
|
available_model_.setStringList(all_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-12-10 10:31:42 +00:00
|
|
|
QString str = toqstr(params()["key"]);
|
2007-03-25 01:32:12 +00:00
|
|
|
if (str.isEmpty())
|
|
|
|
cited_keys_.clear();
|
|
|
|
else
|
|
|
|
cited_keys_ = str.split(",");
|
|
|
|
selected_model_.setStringList(cited_keys_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
void QCitation::findKey(QString const & str, bool only_keys,
|
2007-08-20 16:30:02 +00:00
|
|
|
docstring field, docstring entryType,
|
|
|
|
bool case_sensitive, bool reg_exp, bool reset)
|
2006-03-25 21:26:09 +00:00
|
|
|
{
|
2007-03-25 01:32:12 +00:00
|
|
|
// Used for optimisation: store last searched string.
|
|
|
|
static QString last_searched_string;
|
|
|
|
// Used to disable the above optimisation.
|
|
|
|
static bool last_case_sensitive;
|
|
|
|
static bool last_reg_exp;
|
|
|
|
// Reset last_searched_string in case of changed option.
|
|
|
|
if (last_case_sensitive != case_sensitive
|
|
|
|
|| last_reg_exp != reg_exp) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI) << "QCitation::findKey: optimisation disabled!" << std::endl;
|
2007-03-25 01:32:12 +00:00
|
|
|
last_searched_string.clear();
|
|
|
|
}
|
|
|
|
// save option for next search.
|
|
|
|
last_case_sensitive = case_sensitive;
|
|
|
|
last_reg_exp = reg_exp;
|
|
|
|
|
|
|
|
Qt::CaseSensitivity qtcase = case_sensitive?
|
|
|
|
Qt::CaseSensitive: Qt::CaseInsensitive;
|
|
|
|
QStringList keys;
|
|
|
|
// If new string (str) contains the last searched one...
|
2007-08-20 16:30:02 +00:00
|
|
|
if (!reset &&
|
|
|
|
!last_searched_string.isEmpty() &&
|
|
|
|
str.size() > 1 &&
|
|
|
|
str.contains(last_searched_string, qtcase))
|
2007-03-25 01:32:12 +00:00
|
|
|
// ... then only search within already found list.
|
|
|
|
keys = available_model_.stringList();
|
|
|
|
else
|
|
|
|
// ... else search all keys.
|
|
|
|
keys = all_keys_;
|
|
|
|
// save searched string for next search.
|
|
|
|
last_searched_string = str;
|
|
|
|
|
|
|
|
QStringList result;
|
2007-08-20 16:30:02 +00:00
|
|
|
|
|
|
|
//First, filter by entryType, which will be faster than
|
|
|
|
//what follows, so we may get to do that on less.
|
|
|
|
vector<docstring> keyVector = to_docstring_vector(keys);
|
|
|
|
filterByEntryType(keyVector, entryType);
|
|
|
|
|
|
|
|
if (str.isEmpty())
|
|
|
|
result = to_qstring_list(keyVector);
|
2007-03-25 01:32:12 +00:00
|
|
|
else
|
2007-08-20 16:30:02 +00:00
|
|
|
result = to_qstring_list(searchKeys(keyVector, only_keys,
|
|
|
|
qstring_to_ucs4(str), field, case_sensitive, reg_exp));
|
|
|
|
|
2007-03-25 01:32:12 +00:00
|
|
|
available_model_.setStringList(result);
|
2006-03-25 21:26:09 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
QStringList QCitation::getFieldsAsQStringList() {
|
|
|
|
return to_qstring_list(availableFields());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList QCitation::getEntriesAsQStringList() {
|
|
|
|
return to_qstring_list(availableEntries());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-11 08:26:43 +00:00
|
|
|
QStringList QCitation::citationStyles(int sel)
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
docstring const key = qstring_to_ucs4(cited_keys_[sel]);
|
2007-03-25 01:32:12 +00:00
|
|
|
return to_qstring_list(getCiteStrings(key));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
|
|
|
|
QString QCitation::getKeyInfo(QString const & sel)
|
|
|
|
{
|
2007-08-20 16:30:02 +00:00
|
|
|
return toqstr(getInfo(qstring_to_ucs4(sel)));
|
2006-06-28 08:28:16 +00:00
|
|
|
}
|
|
|
|
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This third patch just re-factors some code presently in QCitation*. (It also incorporates some bug fixes that have been committed separately.) We're going to use essentially the same set of widgets for choosing modules that is used for choosing citation keys, so we pull the controlling logic out into a new class, QSelectionManager. I did not make this a QWidget. That seemed to me to be overkill, and it would have made things much more complicated, I think...and I'm not all that experienced with Qt, anyway. Anyone who wants to do that is of course welcome.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19860 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-28 16:49:40 +00:00
|
|
|
void QCitation::setCitedKeys()
|
|
|
|
{
|
|
|
|
cited_keys_ = selected_model_.stringList();
|
|
|
|
}
|
|
|
|
|
2006-06-28 08:28:16 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|