Optional content activity settings

This commit is contained in:
Jakub Melka
2019-07-02 16:20:12 +02:00
parent d4ef618c5d
commit e04222fb0b
7 changed files with 287 additions and 5 deletions

View File

@ -111,6 +111,11 @@ Qt::ItemFlags PDFTreeItemModel::flags(const QModelIndex& index) const
}
void PDFOptionalContentTreeItemModel::setActivity(PDFOptionalContentActivity* activity)
{
m_activity = activity;
}
int PDFOptionalContentTreeItemModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
@ -131,7 +136,33 @@ QVariant PDFOptionalContentTreeItemModel::data(const QModelIndex& index, int rol
return item->getText();
case Qt::CheckStateRole:
return Qt::Checked;
{
if (item->getReference() != PDFObjectReference())
{
if (m_activity)
{
switch (m_activity->getState(item->getReference()))
{
case OCState::ON:
return Qt::Checked;
case OCState::OFF:
return Qt::Unchecked;
case OCState::Unknown:
return Qt::PartiallyChecked;
default:
{
Q_ASSERT(false);
break;
}
}
}
return Qt::PartiallyChecked;
}
break;
}
default:
break;
@ -272,4 +303,25 @@ QString PDFOptionalContentTreeItem::getText() const
return QString();
}
bool PDFOptionalContentTreeItemModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if (!index.isValid())
{
return false;
}
if (m_activity && role == Qt::CheckStateRole)
{
const PDFOptionalContentTreeItem* item = static_cast<const PDFOptionalContentTreeItem*>(index.internalPointer());
if (item->getReference() != PDFObjectReference() && !item->isLocked())
{
Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt());
m_activity->setState(item->getReference(), (newState == Qt::Checked) ? OCState::ON : OCState::OFF);
return true;
}
}
return false;
}
} // namespace pdf