53 #include "ui_dialogmdatabase.h"
54 #include "../mapplication.h"
55 #include "../vpatterndb/measurements.h"
59 #include <QSvgRenderer>
65 , ui(new
Ui::DialogMDataBase)
88 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
91 setWindowFlags(Qt::Window);
96 ui->treeWidget->installEventFilter(
this);
109 , ui(new
Ui::DialogMDataBase)
132 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
134 #if defined(Q_OS_MAC)
135 setWindowFlags(Qt::Window);
140 ui->treeWidget->installEventFilter(
this);
190 QString imgUrl(
"<img src=\"wrong.png\" align=\"center\"/>");
191 const QString filePath = QString(
"://diagrams/%1.svg").arg(
MapDiagrams(
qApp->TrVars(), number));
192 if (QFileInfo::exists(filePath))
195 QSvgRenderer renderer;
196 const bool ok = renderer.load(filePath);
199 const QScreen *screen = QGuiApplication::screens().at(0);
202 const QSize defSize = renderer.defaultSize();
205 QImage image(defSize, QImage::Format_RGB32);
206 image.fill(Qt::white);
208 const QRect geometry = screen->geometry();
209 const int baseHeight = 1440;
210 const int imgHeight = geometry.height() * defSize.height() / baseHeight;
212 QImage scaledImg = image.scaledToHeight(imgHeight);
215 QPainter painter(&scaledImg);
216 renderer.render(&painter);
218 QByteArray byteArray;
219 QBuffer buffer(&byteArray);
220 scaledImg.save(&buffer,
"PNG");
221 imgUrl = QString(
"<img src=\"data:image/png;base64,") + byteArray.toBase64() +
"\" align=\"center\"/>";
232 if (event->type() == QEvent::LanguageChange)
235 ui->retranslateUi(
this);
239 QDialog::changeEvent(event);
245 if (target ==
ui->treeWidget && event->type() == QEvent::KeyPress)
247 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
248 switch(keyEvent->key())
252 const QModelIndex model =
ui->treeWidget->indexAbove(
ui->treeWidget->currentIndex());
253 QTreeWidgetItem *item =
ui->treeWidget->itemAbove(
ui->treeWidget->currentItem());
259 const QModelIndex model =
ui->treeWidget->indexBelow(
ui->treeWidget->currentIndex());
260 QTreeWidgetItem *item =
ui->treeWidget->itemBelow(
ui->treeWidget->currentItem());
268 return QDialog::eventFilter(target, event);
275 if (column != 0 && column != -1)
280 if (item->childCount() != 0 && item->checkState(0) != Qt::PartiallyChecked && column != -1)
283 Qt::CheckState state = item->checkState(0);
284 for (
int i = 0; i < item->childCount(); ++i)
286 if (!
measurements.contains(item->child(i)->data(0, Qt::UserRole).toString()))
288 item->child(i)->setCheckState(0, state);
294 item->setCheckState(0, Qt::Checked);
298 else if (item->childCount() == 0 || column == -1)
301 QString itemName = item->data(0, Qt::UserRole).toString();
302 Qt::CheckState state = item->checkState(0);
304 if (state == Qt::CheckState::Unchecked)
308 else if (state == Qt::CheckState::Checked &&
316 QTreeWidgetItem *parent = item->parent();
317 if (parent ==
nullptr)
321 for (
int j = 0; j < parent->childCount(); ++j)
323 if (j != parent->indexOfChild(item)
324 && item->checkState(0) != parent->child(j)->checkState(0))
331 parent->setCheckState(0, Qt::PartiallyChecked);
335 parent->setCheckState(0, item->checkState(0));
345 if ((column != 0 && column != -1) || item ==
nullptr || (item->childCount() != 0 ))
347 ui->textEdit->clear();
351 const QString name = item->data(0, Qt::UserRole).toString();
353 const QString number = trv->
MNumber(name);
355 const QString text = QString(
"<p align=\"center\" style=\"font-variant: normal; font-style: normal; font-weight: "
356 "normal\"> %1 <br clear=\"left\"><b>%2</b>. <i>%3</i></p>"
357 "<p align=\"left\" style=\"font-variant: normal; font-style: normal; font-weight: "
364 ui->textEdit->setHtml(text);
371 const QModelIndex model =
ui->treeWidget->currentIndex();
372 QTreeWidgetItem *item =
ui->treeWidget->currentItem();
375 QAction *actionCollapseAll =
new QAction(tr(
"Collapse All"),
this);
376 connect(actionCollapseAll, &QAction::triggered,
ui->treeWidget, &QTreeWidget::collapseAll);
378 QAction *actionExpandeAll =
new QAction(tr(
"Expand All"),
this);
379 connect(actionExpandeAll, &QAction::triggered,
ui->treeWidget, &QTreeWidget::expandAll);
382 menu.addAction(actionCollapseAll);
383 menu.addAction(actionExpandeAll);
388 globalCheckState() == Qt::Checked ? actionName = tr(
"Check all") : actionName = tr(
"Uncheck all");
390 QAction *actionRecheckState =
new QAction(actionName,
this);
393 menu.addAction(actionRecheckState);
395 menu.exec(
ui->treeWidget->mapToGlobal(pos));
449 const QStringList &groupList,
const QStringList &measurementList)
452 for (
int i=0; i < groupList.size(); ++i)
461 QTreeWidgetItem *group =
new QTreeWidgetItem(
ui->treeWidget);
462 group->setText(0, groupName);
463 group->setToolTip(0, groupName);
464 group->setExpanded(
true);
467 group->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
468 group->setCheckState(0, Qt::Unchecked);
469 group->setBackground(0, QBrush(Qt::lightGray));
479 QTreeWidgetItem *item =
new QTreeWidgetItem(group);
485 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
486 item->setCheckState(0, Qt::Checked);
487 item->setBackground(0, QBrush(QColor(231, 231, 0, 127)));
489 else if (list.contains(name))
491 item->setCheckState(0, Qt::Checked);
495 item->setCheckState(0, Qt::Unchecked);
501 const QString text =
qApp->TrVars()->MNumber(name) +
". " +
qApp->TrVars()->MToUser(name);
502 item->setText(0, text);
503 item->setToolTip(0, text);
504 item->setData(0, Qt::UserRole, name);
510 restoreGeometry(
qApp->SeamlyMeSettings()->getDataBaseGeometry());
516 qApp->SeamlyMeSettings()->setDataBaseGeometry(saveGeometry());
548 bool isMatch =
false;
549 for (
int i=0; i < group->childCount(); ++i)
551 QTreeWidgetItem *item = group->child(i);
558 const bool isHidden = !item->text(0).contains(searchString, Qt::CaseInsensitive);
560 item->setHidden(isHidden);
567 group->setHidden(!group->text(0).contains(searchString, Qt::CaseInsensitive) && !isMatch);
572 const QStringList &list)
574 group->setText(0, groupName);
575 group->setToolTip(0, groupName);
577 for (
int i=0; i<list.size(); ++i)
586 const QString text =
qApp->TrVars()->MNumber(name) +
". " +
qApp->TrVars()->MToUser(name);
588 QTreeWidgetItem *item = group->child(index);
589 item->setText(0, text);
590 item->setToolTip(0, text);
597 group->setCheckState(0, state);
623 if (
groupA->checkState(0) == Qt::Unchecked &&
624 groupB->checkState(0) == Qt::Unchecked &&
625 groupC->checkState(0) == Qt::Unchecked &&
626 groupD->checkState(0) == Qt::Unchecked &&
627 groupE->checkState(0) == Qt::Unchecked &&
628 groupF->checkState(0) == Qt::Unchecked &&
629 groupG->checkState(0) == Qt::Unchecked &&
630 groupH->checkState(0) == Qt::Unchecked &&
631 groupI->checkState(0) == Qt::Unchecked &&
632 groupJ->checkState(0) == Qt::Unchecked &&
633 groupK->checkState(0) == Qt::Unchecked &&
634 groupL->checkState(0) == Qt::Unchecked &&
635 groupM->checkState(0) == Qt::Unchecked &&
636 groupN->checkState(0) == Qt::Unchecked &&
637 groupO->checkState(0) == Qt::Unchecked &&
638 groupP->checkState(0) == Qt::Unchecked &&
639 groupQ->checkState(0) == Qt::Unchecked)
643 else if (
groupA->checkState(0) == Qt::Checked &&
644 groupB->checkState(0) == Qt::Checked &&
645 groupC->checkState(0) == Qt::Checked &&
646 groupD->checkState(0) == Qt::Checked &&
647 groupE->checkState(0) == Qt::Checked &&
648 groupF->checkState(0) == Qt::Checked &&
649 groupG->checkState(0) == Qt::Checked &&
650 groupH->checkState(0) == Qt::Checked &&
651 groupI->checkState(0) == Qt::Checked &&
652 groupJ->checkState(0) == Qt::Checked &&
653 groupK->checkState(0) == Qt::Checked &&
654 groupL->checkState(0) == Qt::Checked &&
655 groupM->checkState(0) == Qt::Checked &&
656 groupN->checkState(0) == Qt::Checked &&
657 groupO->checkState(0) == Qt::Checked &&
658 groupP->checkState(0) == Qt::Checked &&
659 groupQ->checkState(0) == Qt::Checked)
661 return Qt::Unchecked;
666 return Qt::Unchecked;
void addMeasurement(QTreeWidgetItem *group, const QString &groupName, const QStringList &newMeasurements)
void filterGroup(QTreeWidgetItem *group, const QString &searchString)
void updateChecks(QTreeWidgetItem *item, int column)
QStringList getNewMeasurementNames() const
void initDataBase(const QStringList &measurements=QStringList())
virtual bool eventFilter(QObject *target, QEvent *event) Q_DECL_OVERRIDE
Qt::CheckState globalCheckState() const
Q_REQUIRED_RESULT QTreeWidgetItem * addMeasurementGroup(const QString &text)
void changeCheckState(QTreeWidgetItem *group, Qt::CheckState state)
MeasurementDatabaseDialog(const QStringList &measurements, QWidget *parent=nullptr)
void treeContextMenu(const QPoint &pos)
void retranslateMeasurement(QTreeWidgetItem *group, int index, const QString &name)
void retranslateGroup(QTreeWidgetItem *group, const QString &groupName, const QStringList &measurements)
QStringList newMeasurements
virtual void changeEvent(QEvent *event) Q_DECL_OVERRIDE
virtual ~MeasurementDatabaseDialog() Q_DECL_OVERRIDE
void showDescription(QTreeWidgetItem *item, int column)
void filterGroups(const QString searchString)
void initGroup(QTreeWidgetItem **group, const QString &groupName, const QStringList &groupList, const QStringList &measurementList=QStringList())
static QString imageUrl(const QString &number)
QString guiText(const QString &measurement) const
QString MNumber(const QString &measurement) const
QString Description(const QString &measurement) const
QString MapDiagrams(const VTranslateMeasurements *trM, const QString &number)