Issue #103: Bookmark sidebar greyed out if a bookmark is not already present

This commit is contained in:
Jakub Melka 2023-11-08 19:24:04 +01:00
parent 2584227373
commit 6fe978f031
5 changed files with 31 additions and 3 deletions

View File

@ -415,6 +415,7 @@ void PDFOutlineTreeItemModel::update()
{
outlineRoot = m_document->getCatalog()->getOutlineRootPtr();
}
if (outlineRoot)
{
if (m_editable)
@ -426,7 +427,15 @@ void PDFOutlineTreeItemModel::update()
}
else
{
m_rootItem.reset();
if (m_editable && m_document)
{
outlineRoot.reset(new pdf::PDFOutlineItem());
m_rootItem.reset(new PDFOutlineTreeItem(nullptr, qMove(outlineRoot)));
}
else
{
m_rootItem.reset();
}
}
endResetModel();
@ -653,9 +662,12 @@ bool PDFOutlineTreeItemModel::insertRows(int row, int count, const QModelIndex&
{
QSharedPointer<PDFOutlineItem> outlineItem(new PDFOutlineItem());
outlineItem->setTitle(tr("Item %1").arg(row + 1));
PDFOutlineTreeItem* newTreeItem = new PDFOutlineTreeItem(item, qMove(outlineItem));
PDFOutlineTreeItem* newTreeItem = new PDFOutlineTreeItem(item, outlineItem);
item->insertCreatedChild(row, newTreeItem);
PDFOutlineItem* parentItem = item->getOutlineItem();
parentItem->insertChild(row, outlineItem);
++row;
--count;
}
@ -677,6 +689,7 @@ bool PDFOutlineTreeItemModel::removeRows(int row, int count, const QModelIndex&
PDFOutlineTreeItem* item = parent.isValid() ? static_cast<PDFOutlineTreeItem*>(parent.internalPointer()) : static_cast<PDFOutlineTreeItem*>(m_rootItem.get());
while (count > 0)
{
item->getOutlineItem()->removeChild(row);
delete item->takeChild(row);
--count;
}

View File

@ -213,6 +213,8 @@ public:
const PDFOutlineItem* getRootOutlineItem() const;
bool isEditable() const { return m_editable; }
private:
QIcon m_icon;
bool m_editable;

View File

@ -179,6 +179,16 @@ QSharedPointer<PDFOutlineItem> PDFOutlineItem::clone() const
return result;
}
void PDFOutlineItem::insertChild(size_t index, QSharedPointer<PDFOutlineItem> item)
{
m_children.insert(std::next(m_children.begin(), index), item);
}
void PDFOutlineItem::removeChild(size_t index)
{
m_children.erase(std::next(m_children.begin(), index));
}
bool PDFOutlineItem::isFontBold() const
{
return m_fontBold;

View File

@ -67,6 +67,9 @@ public:
QSharedPointer<PDFOutlineItem> clone() const;
void insertChild(size_t index, QSharedPointer<PDFOutlineItem> item);
void removeChild(size_t index);
private:
static void parseImpl(const PDFObjectStorage* storage,
PDFOutlineItem* parent,

View File

@ -260,7 +260,7 @@ bool PDFSidebarWidget::isEmpty(Page page) const
return true;
case Bookmarks:
return m_outlineTreeModel->isEmpty();
return m_outlineTreeModel->isEmpty() && (!m_document || !m_outlineTreeModel->isEditable());
case Thumbnails:
return m_thumbnailsModel->isEmpty();