PDF4QT/PdfForQtLib/sources/pdfrenderingerrorswidget.cpp

107 lines
3.5 KiB
C++
Raw Normal View History

2020-01-18 11:38:54 +01:00
// Copyright (C) 2019-2020 Jakub Melka
2019-02-24 19:42:00 +01:00
//
// This file is part of PdfForQt.
//
// PdfForQt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PdfForQt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "pdfrenderingerrorswidget.h"
#include "pdfdrawwidget.h"
#include "ui_pdfrenderingerrorswidget.h"
namespace pdf
{
PDFRenderingErrorsWidget::PDFRenderingErrorsWidget(QWidget* parent, PDFWidget* pdfWidget) :
QDialog(parent),
ui(new Ui::PDFRenderingErrorsWidget)
{
ui->setupUi(this);
ui->renderErrorsTreeWidget->setColumnCount(3);
ui->renderErrorsTreeWidget->setColumnWidth(0, 100);
ui->renderErrorsTreeWidget->setColumnWidth(1, 300);
ui->renderErrorsTreeWidget->setHeaderLabels({ tr("Page"), tr("Error type"), tr("Description") });
Q_ASSERT(pdfWidget);
std::vector<PDFInteger> currentPages = pdfWidget->getDrawWidget()->getCurrentPages();
qSort(currentPages);
QTreeWidgetItem* scrollToItem = nullptr;
const PDFWidget::PageRenderingErrors* pageRenderingErrors = pdfWidget->getPageRenderingErrors();
for (const auto& pageRenderingError : *pageRenderingErrors)
{
const PDFInteger pageIndex = pageRenderingError.first;
QTreeWidgetItem* root = new QTreeWidgetItem(ui->renderErrorsTreeWidget, QStringList() << QString::number(pageIndex + 1) << QString() << QString());
for (const PDFRenderError& error : pageRenderingError.second)
{
QString typeString;
switch (error.type)
{
case RenderErrorType::Error:
{
typeString = tr("Error");
2019-04-30 14:39:48 +02:00
break;
}
case RenderErrorType::Warning:
{
typeString = tr("Warning");
2019-02-24 19:42:00 +01:00
break;
}
case RenderErrorType::NotImplemented:
{
typeString = tr("Not implemented");
break;
}
2019-09-29 15:44:35 +02:00
case RenderErrorType::NotSupported:
{
typeString = tr("Not supported");
break;
}
2019-02-24 19:42:00 +01:00
default:
{
Q_ASSERT(false);
break;
}
}
new QTreeWidgetItem(root, QStringList() << QString() << typeString << error.message);
}
bool isCurrentPage = std::binary_search(currentPages.cbegin(), currentPages.cend(), pageIndex);
ui->renderErrorsTreeWidget->setItemExpanded(root, isCurrentPage);
if (isCurrentPage && !scrollToItem)
{
scrollToItem = root;
}
}
if (scrollToItem)
{
ui->renderErrorsTreeWidget->scrollToItem(scrollToItem, QAbstractItemView::EnsureVisible);
}
}
PDFRenderingErrorsWidget::~PDFRenderingErrorsWidget()
{
delete ui;
}
} // namespace pdf