mirror of https://github.com/JakubMelka/PDF4QT.git
Object stastistics (first part)
This commit is contained in:
parent
7264a45e30
commit
b8464ed4fa
|
@ -519,6 +519,28 @@ qint64 PDFDocumentWriter::getDocumentFileSize(const PDFDocument* document)
|
|||
return -1;
|
||||
}
|
||||
|
||||
qint64 PDFDocumentWriter::getObjectSize(const PDFDocument* document, PDFObjectReference reference)
|
||||
{
|
||||
const PDFObject& object = document->getObjectByReference(reference);
|
||||
|
||||
if (object.isNull())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PDFSizeCounterIODevice device(nullptr);
|
||||
|
||||
device.open(QIODevice::WriteOnly);
|
||||
|
||||
PDFWriteObjectVisitor visitor(&device);
|
||||
writeObjectHeader(&device, reference);
|
||||
object.accept(&visitor);
|
||||
writeObjectFooter(&device);
|
||||
|
||||
device.close();
|
||||
return device.pos();
|
||||
}
|
||||
|
||||
QByteArray PDFDocumentWriter::getSerializedObject(const PDFObject& object)
|
||||
{
|
||||
QBuffer buffer;
|
||||
|
|
|
@ -63,14 +63,19 @@ public:
|
|||
/// \param document Document
|
||||
static qint64 getDocumentFileSize(const PDFDocument* document);
|
||||
|
||||
/// Calculates size estimate of an object. If object is null, then zero is returned.
|
||||
/// \param document Document
|
||||
/// \param reference Reference
|
||||
static qint64 getObjectSize(const PDFDocument* document, PDFObjectReference reference);
|
||||
|
||||
/// Writes an object to byte array, without object header/footer
|
||||
/// \param object Object to be written
|
||||
static QByteArray getSerializedObject(const PDFObject& object);
|
||||
|
||||
private:
|
||||
void writeCRLF(QIODevice* device);
|
||||
void writeObjectHeader(QIODevice* device, PDFObjectReference reference);
|
||||
void writeObjectFooter(QIODevice* device);
|
||||
static void writeCRLF(QIODevice* device);
|
||||
static void writeObjectHeader(QIODevice* device, PDFObjectReference reference);
|
||||
static void writeObjectFooter(QIODevice* device);
|
||||
|
||||
/// Progress indicator
|
||||
PDFProgress* m_progress;
|
||||
|
|
|
@ -174,10 +174,13 @@ public:
|
|||
Array,
|
||||
Dictionary,
|
||||
Stream,
|
||||
Reference
|
||||
Reference,
|
||||
|
||||
// Last type mark
|
||||
LastType
|
||||
};
|
||||
|
||||
static std::vector<Type> getTypes() { return { Type::Null, Type::Bool, Type::Int, Type::Real, Type::String, Type::Name, Type::Array, Type::Dictionary, Type::Stream, Type::Reference }; }
|
||||
static constexpr auto getTypes() { return std::array{ Type::Null, Type::Bool, Type::Int, Type::Real, Type::String, Type::Name, Type::Array, Type::Dictionary, Type::Stream, Type::Reference }; }
|
||||
|
||||
typedef std::shared_ptr<PDFObjectContent> PDFObjectContentPointer;
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "pdfobjectutils.h"
|
||||
#include "pdfvisitor.h"
|
||||
#include "pdfexecutionpolicy.h"
|
||||
#include "pdfdocumentwriter.h"
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
@ -362,6 +364,59 @@ std::vector<PDFObjectReference> PDFObjectClassifier::getObjectsByType(Type type)
|
|||
return result;
|
||||
}
|
||||
|
||||
PDFObjectClassifier::Statistics PDFObjectClassifier::calculateStatistics(const PDFDocument* document) const
|
||||
{
|
||||
Statistics result;
|
||||
|
||||
// Jakub Melka: prepare statistics map
|
||||
result.statistics[None];
|
||||
|
||||
for (uint i = 0; i < 32; ++i)
|
||||
{
|
||||
uint32_t mask = 1 << i;
|
||||
if (m_allTypesUsed & mask)
|
||||
{
|
||||
result.statistics[Type(mask)];
|
||||
}
|
||||
}
|
||||
|
||||
auto processEntry = [document, &result](const Classification& entry)
|
||||
{
|
||||
const PDFObject& object = document->getObjectByReference(entry.reference);
|
||||
|
||||
if (object.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type type = Type(uint32_t(entry.types));
|
||||
if (!result.statistics.count(type))
|
||||
{
|
||||
type = None;
|
||||
}
|
||||
|
||||
Q_ASSERT(result.statistics.count(type));
|
||||
|
||||
const qint64 objectSize = PDFDocumentWriter::getObjectSize(document, entry.reference);
|
||||
|
||||
StatisticsItem& statisticsItem = result.statistics.at(type);
|
||||
statisticsItem.count.fetch_add(1);
|
||||
statisticsItem.bytes.fetch_add(objectSize);
|
||||
};
|
||||
|
||||
PDFExecutionPolicy::execute(PDFExecutionPolicy::Scope::Unknown, m_classification.cbegin(), m_classification.cend(), processEntry);
|
||||
|
||||
PDFStatisticsCollector collector;
|
||||
PDFApplyVisitor(*document, &collector);
|
||||
|
||||
for (PDFObject::Type objectType : PDFObject::getTypes())
|
||||
{
|
||||
result.objectCountByType[size_t(objectType)] = collector.getObjectCount(objectType);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PDFObjectClassifier::mark(PDFObjectReference reference, Type type)
|
||||
{
|
||||
Q_ASSERT(hasObject(reference));
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
|
@ -148,6 +149,31 @@ public:
|
|||
/// \param type Type
|
||||
std::vector<PDFObjectReference> getObjectsByType(Type type) const;
|
||||
|
||||
struct StatisticsItem
|
||||
{
|
||||
inline StatisticsItem() :
|
||||
count(0),
|
||||
bytes(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::atomic<qint64> count;
|
||||
std::atomic<qint64> bytes;
|
||||
};
|
||||
|
||||
struct Statistics
|
||||
{
|
||||
std::array<qint64, size_t(PDFObject::Type::LastType)> objectCountByType = { };
|
||||
std::map<Type, StatisticsItem> statistics;
|
||||
};
|
||||
|
||||
/// Calculate document statistics. Document classification must be
|
||||
/// performed before this function is called, otherwise result is undefined.
|
||||
/// \param document Document
|
||||
/// \returns Calculated statistics of each object type
|
||||
Statistics calculateStatistics(const PDFDocument* document) const;
|
||||
|
||||
private:
|
||||
struct Classification
|
||||
{
|
||||
|
|
|
@ -50,11 +50,7 @@ void PDFAbstractVisitor::acceptStream(const PDFStream* stream)
|
|||
|
||||
PDFStatisticsCollector::PDFStatisticsCollector()
|
||||
{
|
||||
// We must avoid to allocate map item
|
||||
for (PDFObject::Type type : PDFObject::getTypes())
|
||||
{
|
||||
m_statistics.emplace(std::make_pair(type, Statistics()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PDFStatisticsCollector::visitNull()
|
||||
|
@ -82,7 +78,7 @@ void PDFStatisticsCollector::visitReal(PDFReal value)
|
|||
|
||||
void PDFStatisticsCollector::visitString(PDFStringRef string)
|
||||
{
|
||||
Statistics& statistics = m_statistics[PDFObject::Type::String];
|
||||
Statistics& statistics = m_statistics[size_t(PDFObject::Type::String)];
|
||||
if (string.inplaceString)
|
||||
{
|
||||
collectStatisticsOfSimpleObject(PDFObject::Type::String);
|
||||
|
@ -95,7 +91,7 @@ void PDFStatisticsCollector::visitString(PDFStringRef string)
|
|||
|
||||
void PDFStatisticsCollector::visitName(PDFStringRef name)
|
||||
{
|
||||
Statistics& statistics = m_statistics[PDFObject::Type::Name];
|
||||
Statistics& statistics = m_statistics[size_t(PDFObject::Type::Name)];
|
||||
if (name.inplaceString)
|
||||
{
|
||||
collectStatisticsOfSimpleObject(PDFObject::Type::Name);
|
||||
|
@ -108,7 +104,7 @@ void PDFStatisticsCollector::visitName(PDFStringRef name)
|
|||
|
||||
void PDFStatisticsCollector::visitArray(const PDFArray* array)
|
||||
{
|
||||
Statistics& statistics = m_statistics[PDFObject::Type::Array];
|
||||
Statistics& statistics = m_statistics[size_t(PDFObject::Type::Array)];
|
||||
statistics.count += 1;
|
||||
statistics.memoryConsumptionEstimate += sizeof(PDFObject) + sizeof(PDFArray);
|
||||
|
||||
|
@ -122,7 +118,7 @@ void PDFStatisticsCollector::visitArray(const PDFArray* array)
|
|||
|
||||
void PDFStatisticsCollector::visitDictionary(const PDFDictionary* dictionary)
|
||||
{
|
||||
Statistics& statistics = m_statistics[PDFObject::Type::Dictionary];
|
||||
Statistics& statistics = m_statistics[size_t(PDFObject::Type::Dictionary)];
|
||||
collectStatisticsOfDictionary(statistics, dictionary);
|
||||
|
||||
acceptDictionary(dictionary);
|
||||
|
@ -130,7 +126,7 @@ void PDFStatisticsCollector::visitDictionary(const PDFDictionary* dictionary)
|
|||
|
||||
void PDFStatisticsCollector::visitStream(const PDFStream* stream)
|
||||
{
|
||||
Statistics& statistics = m_statistics[PDFObject::Type::Stream];
|
||||
Statistics& statistics = m_statistics[size_t(PDFObject::Type::Stream)];
|
||||
collectStatisticsOfDictionary(statistics, stream->getDictionary());
|
||||
|
||||
const QByteArray& byteArray = *stream->getContent();
|
||||
|
@ -190,7 +186,7 @@ void PDFStatisticsCollector::collectStatisticsOfString(const PDFString* string,
|
|||
|
||||
void PDFStatisticsCollector::collectStatisticsOfSimpleObject(PDFObject::Type type)
|
||||
{
|
||||
Statistics& statistics = m_statistics[type];
|
||||
Statistics& statistics = m_statistics[size_t(type)];
|
||||
statistics.count += 1;
|
||||
statistics.memoryConsumptionEstimate += sizeof(PDFObject);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,13 @@ public:
|
|||
|
||||
struct Statistics
|
||||
{
|
||||
explicit constexpr Statistics() = default;
|
||||
inline constexpr Statistics() :
|
||||
count(0),
|
||||
memoryConsumptionEstimate(0),
|
||||
memoryOverheadEstimate(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// This constructor must not be used while \p other is write-accessed from another thread.
|
||||
/// We use relaxed memory order, because we assume this constructor is used only while
|
||||
|
@ -106,9 +112,9 @@ public:
|
|||
|
||||
}
|
||||
|
||||
std::atomic_uint64_t count = 0;
|
||||
std::atomic_uint64_t memoryConsumptionEstimate = 0;
|
||||
std::atomic_uint64_t memoryOverheadEstimate = 0;
|
||||
std::atomic<qint64> count = 0;
|
||||
std::atomic<qint64> memoryConsumptionEstimate = 0;
|
||||
std::atomic<qint64> memoryOverheadEstimate = 0;
|
||||
};
|
||||
|
||||
virtual void visitNull() override;
|
||||
|
@ -122,12 +128,14 @@ public:
|
|||
virtual void visitStream(const PDFStream* stream) override;
|
||||
virtual void visitReference(const PDFObjectReference reference) override;
|
||||
|
||||
qint64 getObjectCount(PDFObject::Type type) const { return m_statistics[size_t(type)].count; }
|
||||
|
||||
private:
|
||||
void collectStatisticsOfSimpleObject(PDFObject::Type type);
|
||||
void collectStatisticsOfString(const PDFString* string, Statistics& statistics);
|
||||
void collectStatisticsOfDictionary(Statistics& statistics, const PDFDictionary* dictionary);
|
||||
|
||||
std::map<PDFObject::Type, Statistics> m_statistics;
|
||||
std::array<Statistics, size_t(PDFObject::Type::LastType)> m_statistics = { };
|
||||
};
|
||||
|
||||
template<typename Visitor, PDFAbstractVisitor::Strategy strategy>
|
||||
|
|
|
@ -35,14 +35,18 @@ CONFIG += c++11
|
|||
SOURCES += \
|
||||
objectinspectordialog.cpp \
|
||||
objectinspectorplugin.cpp \
|
||||
objectstatisticsdialog.cpp \
|
||||
objectviewerwidget.cpp \
|
||||
pdfobjectinspectortreeitemmodel.cpp
|
||||
pdfobjectinspectortreeitemmodel.cpp \
|
||||
statisticsgraphwidget.cpp
|
||||
|
||||
HEADERS += \
|
||||
objectinspectordialog.h \
|
||||
objectinspectorplugin.h \
|
||||
objectstatisticsdialog.h \
|
||||
objectviewerwidget.h \
|
||||
pdfobjectinspectortreeitemmodel.h
|
||||
pdfobjectinspectortreeitemmodel.h \
|
||||
statisticsgraphwidget.h
|
||||
|
||||
CONFIG += force_debug_info
|
||||
|
||||
|
@ -54,4 +58,6 @@ RESOURCES += \
|
|||
|
||||
FORMS += \
|
||||
objectinspectordialog.ui \
|
||||
objectviewerwidget.ui
|
||||
objectstatisticsdialog.ui \
|
||||
objectviewerwidget.ui \
|
||||
statisticsgraphwidget.ui
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<RCC>
|
||||
<qresource prefix="/pdfplugins/objectinspector">
|
||||
<file>object-inspector.svg</file>
|
||||
<file>object-statistics.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="30mm"
|
||||
height="30mm"
|
||||
viewBox="0 0 30 30"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||
sodipodi:docname="object-statistics.svg">
|
||||
<defs
|
||||
id="defs2">
|
||||
<inkscape:path-effect
|
||||
effect="spiro"
|
||||
id="path-effect831"
|
||||
is_visible="true" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="7.919596"
|
||||
inkscape:cx="110.52031"
|
||||
inkscape:cy="57.025756"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2035"
|
||||
inkscape:window-x="-13"
|
||||
inkscape:window-y="-13"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
<cc:license
|
||||
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
|
||||
<dc:creator>
|
||||
<cc:Agent>
|
||||
<dc:title>Jakub Melka</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
</cc:Work>
|
||||
<cc:License
|
||||
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Reproduction" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Distribution" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Notice" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Attribution" />
|
||||
<cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
|
||||
<cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
|
||||
</cc:License>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Vrstva 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-267)">
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="m 11.646391,283.58184 v 0 0"
|
||||
id="path837"
|
||||
inkscape:connector-curvature="0" />
|
||||
<path
|
||||
style="opacity:1;fill:#be0000;fill-opacity:1;stroke:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path859"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="15.239737"
|
||||
sodipodi:cy="282.52869"
|
||||
sodipodi:rx="12"
|
||||
sodipodi:ry="12"
|
||||
sodipodi:start="0"
|
||||
sodipodi:end="0.78539816"
|
||||
d="m 27.239737,282.52869 a 12,12 0 0 1 -3.514719,8.48528 l -8.485281,-8.48528 z" />
|
||||
<path
|
||||
style="opacity:1;fill:#0000a9;fill-opacity:1;stroke:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path861"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="13.936797"
|
||||
sodipodi:cy="283.29706"
|
||||
sodipodi:rx="12"
|
||||
sodipodi:ry="12"
|
||||
sodipodi:start="0.87266463"
|
||||
sodipodi:end="2.3561945"
|
||||
d="M 21.650248,292.48959 A 12,12 0 0 1 5.4515157,291.78234 l 8.4852813,-8.48528 z" />
|
||||
<path
|
||||
style="opacity:1;fill:#cdc800;fill-opacity:1;stroke:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path865"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="13.201805"
|
||||
sodipodi:cy="281.00259"
|
||||
sodipodi:rx="12"
|
||||
sodipodi:ry="12"
|
||||
sodipodi:start="2.443461"
|
||||
sodipodi:end="4.7996554"
|
||||
d="M 4.0092714,288.71604 A 12,12 0 0 1 2.5576751,275.46161 12,12 0 0 1 14.247674,269.04826 l -1.045869,11.95433 z" />
|
||||
<path
|
||||
style="opacity:1;fill:#00be00;fill-opacity:1;stroke:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
id="path867"
|
||||
sodipodi:type="arc"
|
||||
sodipodi:cx="15.167545"
|
||||
sodipodi:cy="281.00259"
|
||||
sodipodi:rx="12"
|
||||
sodipodi:ry="12"
|
||||
sodipodi:start="4.8869219"
|
||||
sodipodi:end="6.1959188"
|
||||
d="m 17.251323,269.1849 a 12,12 0 0 1 9.870559,10.77182 l -11.954337,1.04587 z" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.9 KiB |
|
@ -22,6 +22,7 @@
|
|||
#include "pdfdrawwidget.h"
|
||||
|
||||
#include "objectinspectordialog.h"
|
||||
#include "objectstatisticsdialog.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
|
@ -30,7 +31,8 @@ namespace pdfplugin
|
|||
|
||||
ObjectInspectorPlugin::ObjectInspectorPlugin() :
|
||||
pdf::PDFPlugin(nullptr),
|
||||
m_objectInspectorAction(nullptr)
|
||||
m_objectInspectorAction(nullptr),
|
||||
m_objectStatisticsAction(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -47,6 +49,12 @@ void ObjectInspectorPlugin::setWidget(pdf::PDFWidget* widget)
|
|||
|
||||
connect(m_objectInspectorAction, &QAction::triggered, this, &ObjectInspectorPlugin::onObjectInspectorTriggered);
|
||||
|
||||
m_objectStatisticsAction = new QAction(QIcon(":/pdfplugins/objectinspector/object-statistics.svg"), tr("Object Statistics"), this);
|
||||
m_objectStatisticsAction->setCheckable(false);
|
||||
m_objectStatisticsAction->setObjectName("actionObjectInspector_ObjectStatistics");
|
||||
|
||||
connect(m_objectStatisticsAction, &QAction::triggered, this, &ObjectInspectorPlugin::onObjectStatisticsTriggered);
|
||||
|
||||
updateActions();
|
||||
}
|
||||
|
||||
|
@ -67,7 +75,7 @@ void ObjectInspectorPlugin::setDocument(const pdf::PDFModifiedDocument& document
|
|||
|
||||
std::vector<QAction*> ObjectInspectorPlugin::getActions() const
|
||||
{
|
||||
return { m_objectInspectorAction };
|
||||
return { m_objectInspectorAction, m_objectStatisticsAction };
|
||||
}
|
||||
|
||||
void ObjectInspectorPlugin::onObjectInspectorTriggered()
|
||||
|
@ -77,9 +85,16 @@ void ObjectInspectorPlugin::onObjectInspectorTriggered()
|
|||
dialog.exec();
|
||||
}
|
||||
|
||||
void ObjectInspectorPlugin::onObjectStatisticsTriggered()
|
||||
{
|
||||
ObjectStatisticsDialog dialog(m_document, m_widget);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void ObjectInspectorPlugin::updateActions()
|
||||
{
|
||||
m_objectInspectorAction->setEnabled(m_widget && m_document);
|
||||
m_objectStatisticsAction->setEnabled(m_widget && m_document);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,10 +43,12 @@ public:
|
|||
|
||||
private:
|
||||
void onObjectInspectorTriggered();
|
||||
void onObjectStatisticsTriggered();
|
||||
|
||||
void updateActions();
|
||||
|
||||
QAction* m_objectInspectorAction;
|
||||
QAction* m_objectStatisticsAction;
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of Pdf4Qt.
|
||||
//
|
||||
// Pdf4Qt 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
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// Pdf4Qt 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 Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "objectstatisticsdialog.h"
|
||||
#include "ui_objectstatisticsdialog.h"
|
||||
|
||||
namespace pdfplugin
|
||||
{
|
||||
|
||||
ObjectStatisticsDialog::ObjectStatisticsDialog(const pdf::PDFDocument* document, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ObjectStatisticsDialog),
|
||||
m_document(document)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
pdf::PDFObjectClassifier classifier;
|
||||
classifier.classify(document);
|
||||
m_statistics = classifier.calculateStatistics(document);
|
||||
}
|
||||
|
||||
ObjectStatisticsDialog::~ObjectStatisticsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
} // namespace pdfplugin
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of Pdf4Qt.
|
||||
//
|
||||
// Pdf4Qt 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
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// Pdf4Qt 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 Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef OBJECTSTATISTICSDIALOG_H
|
||||
#define OBJECTSTATISTICSDIALOG_H
|
||||
|
||||
#include "pdfdocument.h"
|
||||
#include "pdfobjectutils.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ObjectStatisticsDialog;
|
||||
}
|
||||
|
||||
namespace pdfplugin
|
||||
{
|
||||
|
||||
class ObjectStatisticsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ObjectStatisticsDialog(const pdf::PDFDocument* document, QWidget* parent);
|
||||
virtual ~ObjectStatisticsDialog() override;
|
||||
|
||||
private:
|
||||
Ui::ObjectStatisticsDialog* ui;
|
||||
|
||||
enum StatisticsType
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
const pdf::PDFDocument* m_document;
|
||||
pdf::PDFObjectClassifier::Statistics m_statistics;
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
||||
#endif // OBJECTSTATISTICSDIALOG_H
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ObjectStatisticsDialog</class>
|
||||
<widget class="QDialog" name="ObjectStatisticsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>924</width>
|
||||
<height>504</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="pdfplugin::StatisticsGraphWidget" name="graphWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>pdfplugin::StatisticsGraphWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>StatisticsGraphWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of Pdf4Qt.
|
||||
//
|
||||
// Pdf4Qt 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
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// Pdf4Qt 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 Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "statisticsgraphwidget.h"
|
||||
#include "ui_statisticsgraphwidget.h"
|
||||
|
||||
namespace pdfplugin
|
||||
{
|
||||
|
||||
StatisticsGraphWidget::StatisticsGraphWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::StatisticsGraphWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
StatisticsGraphWidget::~StatisticsGraphWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
} // namespace pdfplugin
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2021 Jakub Melka
|
||||
//
|
||||
// This file is part of Pdf4Qt.
|
||||
//
|
||||
// Pdf4Qt 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
|
||||
// with the written consent of the copyright owner, any later version.
|
||||
//
|
||||
// Pdf4Qt 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 Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef STATISTICSGRAPHWIDGET_H
|
||||
#define STATISTICSGRAPHWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class StatisticsGraphWidget;
|
||||
}
|
||||
|
||||
namespace pdfplugin
|
||||
{
|
||||
|
||||
class StatisticsGraphWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StatisticsGraphWidget(QWidget* parent);
|
||||
virtual ~StatisticsGraphWidget() override;
|
||||
|
||||
private:
|
||||
Ui::StatisticsGraphWidget* ui;
|
||||
};
|
||||
|
||||
} // namespace pdfplugin
|
||||
|
||||
#endif // STATISTICSGRAPHWIDGET_H
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>StatisticsGraphWidget</class>
|
||||
<widget class="QWidget" name="StatisticsGraphWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue