Paste P602

Okular patch that doesn't compile, but why?
ActivePublic

Authored by ngraham on May 30 2020, 8:38 PM.
diff --git core/document.cpp core/document.cpp
index 881a4854a..1dcacd278 100644
--- core/document.cpp
+++ core/document.cpp
@@ -165,9 +165,7 @@ QString DocumentPrivate::pagesSizeString() const
{
if (m_generator->pagesSizeMetric() != Generator::None)
{
- QSizeF size = m_parent->allPagesSize();
- if (size.isValid()) return localizedSize(size);
- else return i18nc("Used in this context: 'Page sizes: Multiple'", "Multiple");
+ return m_parent->allPagesSize();
}
else return QString();
}
@@ -3308,7 +3306,7 @@ Rotation Document::rotation() const
return d->m_rotation;
}
-QSizeF Document::allPagesSize() const
+bool Document::allPagesHaveSameSize() const
{
bool allPagesSameSize = true;
QSizeF size;
@@ -3321,10 +3319,10 @@ QSizeF Document::allPagesSize() const
allPagesSameSize = (size == QSizeF(p->width(), p->height()));
}
}
- if (allPagesSameSize) return size;
- else return QSizeF();
+ return allPagesSameSize;
}
+
QString Document::pageSizeString(int page) const
{
if (d->m_generator)
@@ -3338,6 +3336,34 @@ QString Document::pageSizeString(int page) const
return QString();
}
+QString Document::allPagesSize() const
+{
+ if (allPagesHaveSameSize()) {
+ return pageSizeString(0);
+ }
+
+ QSizeF size;
+ QHash<QSizeF, int> pageSizeFrequencies;
+ for (int i = 0; i < d->m_pagesVector.count(); ++i)
+ {
+ const Page *p = d->m_pagesVector.at(i);
+ size = QSizeF(p->width(), p->height());
+ // Grr why does this not work
+ if (pageSizeFrequencies.contains(size)) pageSizeFrequencies[size] = pageSizeFrequencies[size] + 1;
+ else pageSizeFrequencies[size] = 1;
+ }
+
+ QString finalValue = "";
+ QHash<QSizeF, int>::const_iterator i = pageSizeFrequencies.constBegin();
+ while (i != pageSizeFrequencies.constEnd())
+ {
+ finalValue += i18n("%1:%2", d->localizedSize(i.key()), i.value());
+ ++i;
+ }
+
+ return finalValue;
+}
+
static bool shouldCancelRenderingBecauseOf( const PixmapRequest & executingRequest, const PixmapRequest & otherRequest )
{
// New request has higher priority -> cancel
diff --git core/document.h core/document.h
index 73c9c8686..d7770029b 100644
--- core/document.h
+++ core/document.h
@@ -400,10 +400,9 @@ class OKULARCORE_EXPORT Document : public QObject
Rotation rotation() const;
/**
- * If all pages have the same size this method returns it, if the page sizes
- * differ an empty size object is returned.
+ * Returns whether all pages in the document have the same size.
*/
- QSizeF allPagesSize() const;
+ bool allPagesHaveSameSize() const;
/**
* Returns the size string for the given @p page or an empty string
@@ -411,6 +410,13 @@ class OKULARCORE_EXPORT Document : public QObject
*/
QString pageSizeString( int page ) const;
+ /**
+ * Returns a string describing the page sizes in this document.
+ * If all pages have the same size this method returns it; if the page
+ * sizes differ, then each page size is described
+ */
+
+ QString allPagesSize() const;
/**
* Returns the gui client of the generator, if it provides one.
*/
diff --git ui/pagesizelabel.cpp ui/pagesizelabel.cpp
index 2772f6d89..47c8af5f9 100644
--- ui/pagesizelabel.cpp
+++ ui/pagesizelabel.cpp
@@ -27,7 +27,7 @@ void PageSizeLabel::notifyCurrentPageChanged( int previousPage, int currentPage
Q_UNUSED( previousPage )
// if the document is opened
- if ( m_document->pages() > 0 && !m_document->allPagesSize().isValid() )
+ if ( m_document->pages() > 0 && !m_document->allPagesHaveSameSize() )
{
setText( m_document->pageSizeString( currentPage ) );
}
ngraham created this paste.May 30 2020, 8:38 PM
ngraham created this object in space S1 KDE Community.