2 * \file QCitationDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Kalle Dalheimer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "QCitationDialog.h"
16 #include "QCitation.h"
17 #include "qt_helpers.h"
19 #include "bufferparams.h"
22 #include "controllers/ControlCitation.h"
24 #include "support/lstrings.h"
34 using support::getStringFromVector;
35 using support::getVectorFromString;
40 QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
41 : Dialog::View(dialog, _("Citation")), form_(form)
45 setWindowTitle(toqstr("LyX: " + getTitle()));
47 selectedLV->setModel(form_->selected());
48 availableLV->setModel(form_->available());
50 connect(citationStyleCO, SIGNAL(activated(int)),
51 this, SLOT(changed()));
52 connect(fulllistCB, SIGNAL(clicked()),
53 this, SLOT(changed()));
54 connect(forceuppercaseCB, SIGNAL(clicked()),
55 this, SLOT(changed()));
56 connect(textBeforeED, SIGNAL(textChanged(const QString&)),
57 this, SLOT(changed()));
58 connect(textAfterED, SIGNAL(textChanged(const QString&)),
59 this, SLOT(changed()));
63 QCitationDialog::~QCitationDialog()
68 void QCitationDialog::apply()
70 int const choice = std::max(0, citationStyleCO->currentIndex());
72 bool const full = fulllistCB->isChecked();
73 bool const force = forceuppercaseCB->isChecked();
75 QString const before = textBeforeED->text();
76 QString const after = textAfterED->text();
78 form_->apply(choice, full, force, before, after);
82 void QCitationDialog::hide()
88 void QCitationDialog::show()
94 bool QCitationDialog::isVisible() const
96 return QDialog::isVisible();
100 void QCitationDialog::on_okPB_clicked()
107 void QCitationDialog::on_cancelPB_clicked()
113 void QCitationDialog::on_applyPB_clicked()
119 void QCitationDialog::on_restorePB_clicked()
125 void QCitationDialog::update()
127 form_->updateModel();
129 QModelIndex idxa = availableLV->currentIndex();
131 availableLV->setCurrentIndex(availableLV->model()->index(0,0));
133 QModelIndex idx = selectedLV->currentIndex();
134 if (form_->isValid() && !idx.isValid()) {
135 selectedLV->setCurrentIndex(selectedLV->model()->index(0,0));
136 updateInfo(selectedLV->currentIndex());
138 updateInfo(availableLV->currentIndex());
142 textBeforeED->setText(form_->textBefore());
143 textAfterED->setText(form_->textAfter());
150 void QCitationDialog::updateStyle()
152 biblio::CiteEngine const engine = form_->getEngine();
153 bool const natbib_engine =
154 engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
155 engine == biblio::ENGINE_NATBIB_NUMERICAL;
156 bool const basic_engine = engine == biblio::ENGINE_BASIC;
158 fulllistCB->setEnabled(natbib_engine);
159 forceuppercaseCB->setEnabled(natbib_engine);
160 textBeforeED->setEnabled(!basic_engine);
162 string const & command = form_->params().getCmdName();
164 // Find the style of the citekeys
165 vector<biblio::CiteStyle> const & styles =
166 ControlCitation::getCiteStyles();
167 biblio::CitationStyle const cs(command);
169 vector<biblio::CiteStyle>::const_iterator cit =
170 std::find(styles.begin(), styles.end(), cs.style);
172 // restore the latest natbib style
173 if (style_ >= 0 && style_ < citationStyleCO->count())
174 citationStyleCO->setCurrentIndex(style_);
176 citationStyleCO->setCurrentIndex(0);
178 fulllistCB->setChecked(false);
179 forceuppercaseCB->setChecked(false);
181 if (cit != styles.end()) {
182 int const i = int(cit - styles.begin());
183 citationStyleCO->setCurrentIndex(i);
184 fulllistCB->setChecked(cs.full);
185 forceuppercaseCB->setChecked(cs.forceUCase);
190 void QCitationDialog::fillStyles()
192 int const orig = citationStyleCO->currentIndex();
194 citationStyleCO->clear();
196 QStringList selected_keys = form_->selected()->stringList();
197 if (selected_keys.empty()) {
198 citationStyleCO->setEnabled(false);
199 citationStyleLA->setEnabled(false);
203 if (selectedLV->selectionModel()->selectedIndexes().empty())
206 int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem();
208 QStringList sty = form_->citationStyles(curr);
210 bool const basic_engine =
211 (form_->getEngine() == biblio::ENGINE_BASIC);
213 citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
214 citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
216 citationStyleCO->insertItems(0, sty);
218 if (orig != -1 && orig < citationStyleCO->count())
219 citationStyleCO->setCurrentIndex(orig);
223 bool QCitationDialog::isSelected(const QModelIndex & idx)
225 QString const str = idx.data().toString();
226 return !form_->selected()->stringList().filter(str).isEmpty();
230 void QCitationDialog::setButtons()
232 int const arows = availableLV->model()->rowCount();
233 addPB->setEnabled(arows>0 && !isSelected(availableLV->currentIndex()));
235 int const srows = selectedLV->model()->rowCount();
236 int const sel_nr = selectedLV->currentIndex().row();
237 deletePB->setEnabled(sel_nr >= 0);
238 upPB->setEnabled(sel_nr > 0);
239 downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1);
240 applyPB->setEnabled(srows>0);
241 okPB->setEnabled(srows>0);
245 void QCitationDialog::updateInfo(const QModelIndex & idx)
248 QString const keytxt = form_->getKeyInfo(idx.data().toString());
249 infoML->document()->setPlainText(keytxt);
251 infoML->document()->clear();
255 void QCitationDialog::on_selectedLV_clicked(const QModelIndex & idx)
261 void QCitationDialog::on_availableLV_clicked(const QModelIndex & idx)
268 void QCitationDialog::on_availableLV_activated(const QModelIndex & idx)
277 void QCitationDialog::on_addPB_clicked()
279 QModelIndex idx = selectedLV->currentIndex();
280 form_->addKey(availableLV->currentIndex());
282 selectedLV->setCurrentIndex(idx);
287 void QCitationDialog::on_deletePB_clicked()
289 QModelIndex idx = selectedLV->currentIndex();
290 int nrows = selectedLV->model()->rowCount();
292 form_->deleteKey(idx);
294 if (idx.row() == nrows - 1)
295 idx = idx.sibling(idx.row() - 1, idx.column());
298 selectedLV->setCurrentIndex(idx);
300 updateInfo(selectedLV->currentIndex());
305 void QCitationDialog::on_upPB_clicked()
307 QModelIndex idx = selectedLV->currentIndex();
309 selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column()));
314 void QCitationDialog::on_downPB_clicked()
316 QModelIndex idx = selectedLV->currentIndex();
318 selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column()));
323 void QCitationDialog::on_findLE_textChanged(const QString & text)
325 form_->findKey(text);
326 availableLV->setModel(form_->found());
331 void QCitationDialog::changed()
338 } // namespace frontend
341 #include "QCitationDialog_moc.cpp"