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"
21 #include "controllers/ControlCitation.h"
23 #include "support/lstrings.h"
33 using support::getStringFromVector;
34 using support::getVectorFromString;
39 QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
40 : Dialog::View(dialog, "Citation"), form_(form)
44 setWindowTitle(toqstr("LyX: " + getTitle()));
46 selectedLV->setModel(form_->selected());
47 availableLV->setModel(form_->available());
49 connect(citationStyleCO, SIGNAL(activated(int)),
50 this, SLOT(changed()));
51 connect(fulllistCB, SIGNAL(clicked()),
52 this, SLOT(changed()));
53 connect(forceuppercaseCB, SIGNAL(clicked()),
54 this, SLOT(changed()));
55 connect(textBeforeED, SIGNAL(textChanged(const QString&)),
56 this, SLOT(changed()));
57 connect(textAfterED, SIGNAL(textChanged(const QString&)),
58 this, SLOT(changed()));
62 QCitationDialog::~QCitationDialog()
67 void QCitationDialog::apply()
69 int const choice = std::max(0, citationStyleCO->currentIndex());
71 bool const full = fulllistCB->isChecked();
72 bool const force = forceuppercaseCB->isChecked();
74 QString const before = textBeforeED->text();
75 QString const after = textAfterED->text();
77 form_->apply(choice, full, force, before, after);
81 void QCitationDialog::hide()
87 void QCitationDialog::show()
93 bool QCitationDialog::isVisible() const
95 return QDialog::isVisible();
99 void QCitationDialog::on_okPB_clicked()
106 void QCitationDialog::on_cancelPB_clicked()
112 void QCitationDialog::on_applyPB_clicked()
118 void QCitationDialog::on_restorePB_clicked()
124 void QCitationDialog::update()
126 form_->updateModel();
128 QModelIndex idxa = availableLV->currentIndex();
130 availableLV->setCurrentIndex(availableLV->model()->index(0,0));
132 QModelIndex idx = selectedLV->currentIndex();
133 if (form_->isValid() && !idx.isValid()) {
134 selectedLV->setCurrentIndex(selectedLV->model()->index(0,0));
135 updateInfo(selectedLV->currentIndex());
137 updateInfo(availableLV->currentIndex());
141 textBeforeED->setText(form_->textBefore());
142 textAfterED->setText(form_->textAfter());
149 void QCitationDialog::updateStyle()
151 biblio::CiteEngine const engine = form_->getEngine();
152 bool const natbib_engine =
153 engine == biblio::ENGINE_NATBIB_AUTHORYEAR ||
154 engine == biblio::ENGINE_NATBIB_NUMERICAL;
155 bool const basic_engine = engine == biblio::ENGINE_BASIC;
157 fulllistCB->setEnabled(natbib_engine);
158 forceuppercaseCB->setEnabled(natbib_engine);
159 textBeforeED->setEnabled(!basic_engine);
161 string const & command = form_->params().getCmdName();
163 // Find the style of the citekeys
164 vector<biblio::CiteStyle> const & styles =
165 ControlCitation::getCiteStyles();
166 biblio::CitationStyle const cs(command);
168 vector<biblio::CiteStyle>::const_iterator cit =
169 std::find(styles.begin(), styles.end(), cs.style);
171 // restore the latest natbib style
172 if (style_ >= 0 && style_ < citationStyleCO->count())
173 citationStyleCO->setCurrentIndex(style_);
175 citationStyleCO->setCurrentIndex(0);
177 fulllistCB->setChecked(false);
178 forceuppercaseCB->setChecked(false);
180 if (cit != styles.end()) {
181 int const i = int(cit - styles.begin());
182 citationStyleCO->setCurrentIndex(i);
183 fulllistCB->setChecked(cs.full);
184 forceuppercaseCB->setChecked(cs.forceUCase);
189 void QCitationDialog::fillStyles()
191 int const orig = citationStyleCO->currentIndex();
193 citationStyleCO->clear();
195 QStringList selected_keys = form_->selected()->stringList();
196 if (selected_keys.empty()) {
197 citationStyleCO->setEnabled(false);
198 citationStyleLA->setEnabled(false);
202 if (selectedLV->selectionModel()->selectedIndexes().empty())
205 int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem();
207 QStringList sty = form_->citationStyles(curr);
209 bool const basic_engine =
210 (form_->getEngine() == biblio::ENGINE_BASIC);
212 citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
213 citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
215 citationStyleCO->insertItems(0, sty);
217 if (orig != -1 && orig < citationStyleCO->count())
218 citationStyleCO->setCurrentIndex(orig);
222 bool QCitationDialog::isSelected(const QModelIndex & idx)
224 QString const str = idx.data().toString();
225 return !form_->selected()->stringList().filter(str).isEmpty();
229 void QCitationDialog::setButtons()
231 int const arows = availableLV->model()->rowCount();
232 addPB->setEnabled(arows>0 && !isSelected(availableLV->currentIndex()));
234 int const srows = selectedLV->model()->rowCount();
235 int const sel_nr = selectedLV->currentIndex().row();
236 deletePB->setEnabled(sel_nr >= 0);
237 upPB->setEnabled(sel_nr > 0);
238 downPB->setEnabled(sel_nr >= 0 && sel_nr < srows - 1);
239 applyPB->setEnabled(srows>0);
240 okPB->setEnabled(srows>0);
244 void QCitationDialog::updateInfo(const QModelIndex & idx)
247 QString const keytxt = form_->getKeyInfo(idx.data().toString());
248 infoML->document()->setPlainText(keytxt);
250 infoML->document()->clear();
254 void QCitationDialog::on_selectedLV_clicked(const QModelIndex & idx)
260 void QCitationDialog::on_availableLV_clicked(const QModelIndex & idx)
267 void QCitationDialog::on_availableLV_activated(const QModelIndex & idx)
276 void QCitationDialog::on_addPB_clicked()
278 QModelIndex idx = selectedLV->currentIndex();
279 form_->addKey(availableLV->currentIndex());
281 selectedLV->setCurrentIndex(idx);
286 void QCitationDialog::on_deletePB_clicked()
288 QModelIndex idx = selectedLV->currentIndex();
289 int nrows = selectedLV->model()->rowCount();
291 form_->deleteKey(idx);
293 if (idx.row() == nrows - 1)
294 idx = idx.sibling(idx.row() - 1, idx.column());
297 selectedLV->setCurrentIndex(idx);
299 updateInfo(selectedLV->currentIndex());
304 void QCitationDialog::on_upPB_clicked()
306 QModelIndex idx = selectedLV->currentIndex();
308 selectedLV->setCurrentIndex(idx.sibling(idx.row() - 1, idx.column()));
313 void QCitationDialog::on_downPB_clicked()
315 QModelIndex idx = selectedLV->currentIndex();
317 selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column()));
322 void QCitationDialog::on_findLE_textChanged(const QString & text)
324 form_->findKey(text);
325 availableLV->setModel(form_->found());
330 void QCitationDialog::changed()
337 } // namespace frontend
340 #include "QCitationDialog_moc.cpp"