Commit 65adf225 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

qt5: Fix optional content handling with exclusive layers

We were setting the "ui" value correctly, but not the "backend" one
because we were shortcuting on obeyRadioGroups for the off state

Update test to check also for the backend value
parent 157c723c
Pipeline #37284 passed with stages
in 13 minutes and 21 seconds
......@@ -2,7 +2,7 @@
*
* Copyright (C) 2007, Brad Hards <bradh@kde.org>
* Copyright (C) 2008, Pino Toscano <pino@kde.org>
* Copyright (C) 2016, 2018, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2016, 2018, 2019, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2017, Hubert Figuière <hub@figuiere.net>
*
* This program is free software; you can redistribute it and/or modify
......@@ -77,6 +77,8 @@ namespace Poppler
QSet<OptContentItem*> recurseListChildren(bool includeMe = false) const;
OptionalContentGroup *group() const { return m_group; }
private:
OptionalContentGroup *m_group;
QString m_name;
......
......@@ -131,14 +131,16 @@ namespace Poppler
child->m_enabled = state == OptContentItem::On;
child->m_stateBackup = oldState;
}
if (!m_group || !obeyRadioGroups) {
if (!m_group) {
return;
}
if ( state == OptContentItem::On ) {
m_group->setState( OptionalContentGroup::On );
for (int i = 0; i < m_rbGroups.size(); ++i) {
RadioButtonGroup *rbgroup = m_rbGroups.at(i);
changedItems += rbgroup->setItemOn( this );
if (obeyRadioGroups) {
for (int i = 0; i < m_rbGroups.size(); ++i) {
RadioButtonGroup *rbgroup = m_rbGroups.at(i);
changedItems += rbgroup->setItemOn( this );
}
}
} else if ( state == OptContentItem::Off ) {
m_group->setState( OptionalContentGroup::Off );
......
......@@ -4,6 +4,7 @@
#include "GlobalParams.h"
#include <poppler-qt5.h>
#include <poppler-optcontent-private.h>
class TestOptionalContent: public QObject
{
......@@ -399,14 +400,17 @@ void TestOptionalContent::checkRadioButtons()
subindex = optContent->index( 0, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "English" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
subindex = optContent->index( 2, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "Japanese" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Checked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::On );
subindex = optContent->index( 1, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "French" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
// and turning on French should turn off Japanese
QVERIFY( optContent->setData( subindex, QVariant( true ), Qt::CheckStateRole ) );
......@@ -414,14 +418,17 @@ void TestOptionalContent::checkRadioButtons()
subindex = optContent->index( 0, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "English" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
subindex = optContent->index( 2, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "Japanese" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
subindex = optContent->index( 1, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "French" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Checked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::On );
// and turning off French should leave them all off
......@@ -430,14 +437,17 @@ void TestOptionalContent::checkRadioButtons()
subindex = optContent->index( 0, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "English" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
subindex = optContent->index( 2, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "Japanese" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
subindex = optContent->index( 1, 0, index );
QCOMPARE( optContent->data( subindex, Qt::DisplayRole ).toString(), QLatin1String( "French" ) );
QCOMPARE( static_cast<Qt::CheckState>( optContent->data( subindex, Qt::CheckStateRole ).toInt() ), Qt::Unchecked );
QCOMPARE( static_cast<Poppler::OptContentItem *>(subindex.internalPointer())->group()->getState(), OptionalContentGroup::Off );
delete doc;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment