9#include <QtWidgets/QMessageBox>
10#include <QtWidgets/QProgressDialog>
19Qt::ItemFlags CheckableListModel::flags(
const QModelIndex &index)
const
22 return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
26 : QDialog(w), m_model(
this), m_dataModel(dataModel)
29 connect(m_ui.runButton, &QAbstractButton::clicked,
30 this, &BatchTranslationDialog::startTranslation);
31 connect(m_ui.moveUpButton, &QAbstractButton::clicked,
32 this, &BatchTranslationDialog::movePhraseBookUp);
33 connect(m_ui.moveDownButton, &QAbstractButton::clicked,
34 this, &BatchTranslationDialog::movePhraseBookDown);
36 m_ui.phrasebookList->setModel(&m_model);
37 m_ui.phrasebookList->setSelectionBehavior(QAbstractItemView::SelectItems);
38 m_ui.phrasebookList->setSelectionMode(QAbstractItemView::SingleSelection);
44 QString fn = QFileInfo(m_dataModel->srcFileName(modelIndex)).baseName();
45 setWindowTitle(tr(
"Batch Translation of '%1' - Qt Linguist").arg(fn));
47 m_model.insertColumn(0);
48 m_phrasebooks = phrasebooks;
49 m_modelIndex = modelIndex;
50 int count = phrasebooks.size();
51 m_model.insertRows(0, count);
52 for (
int i = 0; i < count; ++i) {
53 QModelIndex idx(m_model.index(i, 0));
54 m_model.setData(idx, phrasebooks[i]->friendlyPhraseBookName());
56 if (phrasebooks[i]->language() != QLocale::C
57 && m_dataModel->language(m_modelIndex) != QLocale::C) {
58 if (phrasebooks[i]->language() != m_dataModel->language(m_modelIndex))
61 sortOrder = (phrasebooks[i]->territory()
62 == m_dataModel
->model(m_modelIndex
)->territory()) ? 0 : 1;
66 m_model.setData(idx, sortOrder == 3 ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole);
67 m_model.setData(idx, sortOrder, Qt::UserRole + 1);
68 m_model.setData(idx, i, Qt::UserRole);
70 m_model.setSortRole(Qt::UserRole + 1);
76 int translatedcount = 0;
77 QCursor oldCursor = cursor();
78 setCursor(Qt::BusyCursor);
81 QProgressDialog *dlgProgress;
82 dlgProgress =
new QProgressDialog(tr(
"Searching, please wait..."), tr(
"&Cancel"), 0, messageCount,
this);
86 const bool translateTranslated = m_ui.ckTranslateTranslated->isChecked();
87 const bool translateFinished = m_ui.ckTranslateFinished->isChecked();
91 && (translateTranslated || m->translation().isEmpty())
95 for (
int b = 0; b < m_model.rowCount(); ++b) {
96 QModelIndex idx(m_model.index(b, 0));
97 QVariant checkState = m_model.data(idx, Qt::CheckStateRole);
98 if (checkState == Qt::Checked) {
99 PhraseBook *pb = m_phrasebooks[m_model.data(idx, Qt::UserRole).toInt()];
100 const auto phrases = pb->phrases();
101 for (
const Phrase *ph : phrases) {
102 if (ph->source() == m->text()) {
103 m_dataModel->setTranslation(it, ph->target());
104 m_dataModel->setFinished(it, m_ui.ckMarkFinished->isChecked());
116 dlgProgress->setValue(msgidx);
117 qApp->processEvents();
118 if (dlgProgress->wasCanceled())
123 setCursor(oldCursor);
125 QMessageBox::information(
this, tr(
"Linguist batch translator"),
126 tr(
"Batch translated %n entries",
"", translatedcount), QMessageBox::Ok);
131 QModelIndexList indexes = m_ui.phrasebookList->selectionModel()->selectedIndexes();
132 if (indexes.size() <= 0)
return;
134 QModelIndex sel = indexes[0];
137 QModelIndex other = m_model.index(row - 1, 0);
138 QMap<
int, QVariant> seldata = m_model.itemData(sel);
139 m_model.setItemData(sel, m_model.itemData(other));
140 m_model.setItemData(other, seldata);
141 m_ui.phrasebookList->selectionModel()->setCurrentIndex(other, QItemSelectionModel::ClearAndSelect);
147 QModelIndexList indexes = m_ui.phrasebookList->selectionModel()->selectedIndexes();
148 if (indexes.size() <= 0)
return;
150 QModelIndex sel = indexes[0];
152 if (row < m_model.rowCount() - 1) {
153 QModelIndex other = m_model.index(row + 1, 0);
154 QMap<
int, QVariant> seldata = m_model.itemData(sel);
155 m_model.setItemData(sel, m_model.itemData(other));
156 m_model.setItemData(other, seldata);
157 m_ui.phrasebookList->selectionModel()->setCurrentIndex(other, QItemSelectionModel::ClearAndSelect);
void setPhraseBooks(const QList< PhraseBook * > &phrasebooks, int modelIndex)
MultiDataModelIterator(MultiDataModel *model, int modelNo, int contextNo=0, int messageNo=0)
MessageItem * current() const
Combined button and popup list for selecting options.