2007-09-09 16:15:33 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "tocmodel.h"
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qdom.h>
|
|
|
|
#include <qlist.h>
|
2016-03-21 23:29:53 +00:00
|
|
|
#include <qtreeview.h>
|
2007-09-09 16:15:33 +00:00
|
|
|
|
2014-10-06 06:15:04 +00:00
|
|
|
#include <QIcon>
|
2007-09-09 16:15:33 +00:00
|
|
|
|
|
|
|
#include "pageitemdelegate.h"
|
|
|
|
#include "core/document.h"
|
|
|
|
#include "core/page.h"
|
|
|
|
|
2007-09-16 17:06:18 +00:00
|
|
|
Q_DECLARE_METATYPE( QModelIndex )
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
struct TOCItem
|
|
|
|
{
|
|
|
|
TOCItem();
|
|
|
|
TOCItem( TOCItem *parent, const QDomElement &e );
|
|
|
|
~TOCItem();
|
|
|
|
|
|
|
|
QString text;
|
|
|
|
Okular::DocumentViewport viewport;
|
|
|
|
QString extFileName;
|
2008-11-30 15:48:01 +00:00
|
|
|
QString url;
|
2007-09-09 16:15:33 +00:00
|
|
|
bool highlight : 1;
|
|
|
|
TOCItem *parent;
|
|
|
|
QList< TOCItem* > children;
|
|
|
|
TOCModelPrivate *model;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TOCModelPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TOCModelPrivate( TOCModel *qq );
|
|
|
|
~TOCModelPrivate();
|
|
|
|
|
|
|
|
void addChildren( const QDomNode &parentNode, TOCItem * parentItem );
|
|
|
|
QModelIndex indexForItem( TOCItem *item ) const;
|
|
|
|
void findViewport( const Okular::DocumentViewport &viewport, TOCItem *item, QList< TOCItem* > &list ) const;
|
|
|
|
|
|
|
|
TOCModel *q;
|
|
|
|
TOCItem *root;
|
|
|
|
bool dirty : 1;
|
|
|
|
Okular::Document *document;
|
2007-09-16 15:00:40 +00:00
|
|
|
QList< TOCItem* > itemsToOpen;
|
2007-09-09 16:15:33 +00:00
|
|
|
QList< TOCItem* > currentPage;
|
2013-01-09 22:31:23 +00:00
|
|
|
TOCModel *m_oldModel;
|
|
|
|
QVector<QModelIndex> m_oldTocExpandedIndexes;
|
2007-09-09 16:15:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TOCItem::TOCItem()
|
2017-09-05 21:27:18 +00:00
|
|
|
: highlight( false ), parent( nullptr ), model( nullptr )
|
2007-09-09 16:15:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TOCItem::TOCItem( TOCItem *_parent, const QDomElement &e )
|
|
|
|
: highlight( false ), parent( _parent )
|
|
|
|
{
|
|
|
|
parent->children.append( this );
|
|
|
|
model = parent->model;
|
|
|
|
text = e.tagName();
|
|
|
|
|
|
|
|
// viewport loading
|
2015-10-29 12:37:11 +00:00
|
|
|
if ( e.hasAttribute( QStringLiteral("Viewport") ) )
|
2007-09-09 16:15:33 +00:00
|
|
|
{
|
|
|
|
// if the node has a viewport, set it
|
2015-10-29 12:37:11 +00:00
|
|
|
viewport = Okular::DocumentViewport( e.attribute( QStringLiteral("Viewport") ) );
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
2015-10-29 12:37:11 +00:00
|
|
|
else if ( e.hasAttribute( QStringLiteral("ViewportName") ) )
|
2007-09-09 16:15:33 +00:00
|
|
|
{
|
|
|
|
// if the node references a viewport, get the reference and set it
|
2015-10-29 12:37:11 +00:00
|
|
|
const QString & page = e.attribute( QStringLiteral("ViewportName") );
|
|
|
|
QString viewport_string = model->document->metaData( QStringLiteral("NamedViewport"), page ).toString();
|
2007-09-09 16:15:33 +00:00
|
|
|
if ( !viewport_string.isEmpty() )
|
|
|
|
viewport = Okular::DocumentViewport( viewport_string );
|
|
|
|
}
|
|
|
|
|
2015-10-29 12:37:11 +00:00
|
|
|
extFileName = e.attribute( QStringLiteral("ExternalFileName") );
|
|
|
|
url = e.attribute( QStringLiteral("URL") );
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOCItem::~TOCItem()
|
|
|
|
{
|
|
|
|
qDeleteAll( children );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOCModelPrivate::TOCModelPrivate( TOCModel *qq )
|
2017-09-05 21:27:18 +00:00
|
|
|
: q( qq ), root( new TOCItem ), dirty( false ), m_oldModel( nullptr )
|
2007-09-09 16:15:33 +00:00
|
|
|
{
|
|
|
|
root->model = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
TOCModelPrivate::~TOCModelPrivate()
|
|
|
|
{
|
|
|
|
delete root;
|
2013-01-09 22:31:23 +00:00
|
|
|
delete m_oldModel;
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TOCModelPrivate::addChildren( const QDomNode & parentNode, TOCItem * parentItem )
|
|
|
|
{
|
2017-09-05 21:27:18 +00:00
|
|
|
TOCItem * currentItem = nullptr;
|
2007-09-09 16:15:33 +00:00
|
|
|
QDomNode n = parentNode.firstChild();
|
|
|
|
while( !n.isNull() )
|
|
|
|
{
|
|
|
|
// convert the node to an element (sure it is)
|
|
|
|
QDomElement e = n.toElement();
|
|
|
|
|
|
|
|
// insert the entry as top level (listview parented) or 2nd+ level
|
|
|
|
currentItem = new TOCItem( parentItem, e );
|
|
|
|
|
|
|
|
// descend recursively and advance to the next node
|
|
|
|
if ( e.hasChildNodes() )
|
|
|
|
addChildren( n, currentItem );
|
|
|
|
|
|
|
|
// open/keep close the item
|
2007-09-16 15:00:40 +00:00
|
|
|
bool isOpen = false;
|
2015-10-29 12:37:11 +00:00
|
|
|
if ( e.hasAttribute( QStringLiteral("Open") ) )
|
|
|
|
isOpen = QVariant( e.attribute( QStringLiteral("Open") ) ).toBool();
|
2008-03-10 20:21:56 +00:00
|
|
|
if ( isOpen )
|
2007-09-16 15:00:40 +00:00
|
|
|
itemsToOpen.append( currentItem );
|
2007-09-09 16:15:33 +00:00
|
|
|
|
|
|
|
n = n.nextSibling();
|
2015-09-23 12:34:12 +00:00
|
|
|
emit q->countChanged();
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex TOCModelPrivate::indexForItem( TOCItem *item ) const
|
|
|
|
{
|
|
|
|
if ( item->parent )
|
|
|
|
{
|
|
|
|
int id = item->parent->children.indexOf( item );
|
|
|
|
if ( id >= 0 && id < item->parent->children.count() )
|
|
|
|
return q->createIndex( id, 0, item );
|
|
|
|
}
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TOCModelPrivate::findViewport( const Okular::DocumentViewport &viewport, TOCItem *item, QList< TOCItem* > &list ) const
|
|
|
|
{
|
2016-03-21 23:29:53 +00:00
|
|
|
TOCItem *todo = item;
|
2007-09-09 16:15:33 +00:00
|
|
|
|
2016-03-21 23:29:53 +00:00
|
|
|
while ( todo )
|
|
|
|
{
|
|
|
|
TOCItem *current = todo;
|
2017-09-05 21:27:18 +00:00
|
|
|
todo = nullptr;
|
|
|
|
TOCItem *pos = nullptr;
|
2016-03-21 23:29:53 +00:00
|
|
|
|
|
|
|
foreach ( TOCItem *child, current->children )
|
|
|
|
{
|
|
|
|
if ( child->viewport.isValid() )
|
|
|
|
{
|
|
|
|
if ( child->viewport.pageNumber <= viewport.pageNumber )
|
|
|
|
{
|
|
|
|
pos = child;
|
|
|
|
if ( child->viewport.pageNumber == viewport.pageNumber )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( pos )
|
|
|
|
{
|
|
|
|
list.append( pos );
|
|
|
|
todo = pos;
|
|
|
|
}
|
|
|
|
}
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOCModel::TOCModel( Okular::Document *document, QObject *parent )
|
|
|
|
: QAbstractItemModel( parent ), d( new TOCModelPrivate( this ) )
|
|
|
|
{
|
|
|
|
d->document = document;
|
2007-09-16 17:06:18 +00:00
|
|
|
|
|
|
|
qRegisterMetaType< QModelIndex >();
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TOCModel::~TOCModel()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2015-09-23 12:34:12 +00:00
|
|
|
QHash<int, QByteArray> TOCModel::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
|
|
|
roles[(int)PageItemDelegate::PageRole] = "page";
|
|
|
|
roles[(int)PageItemDelegate::PageLabelRole] = "pageLabel";
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
int TOCModel::columnCount( const QModelIndex &parent ) const
|
|
|
|
{
|
|
|
|
Q_UNUSED( parent )
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TOCModel::data( const QModelIndex &index, int role ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( index.internalPointer() );
|
|
|
|
switch ( role )
|
|
|
|
{
|
|
|
|
case Qt::DisplayRole:
|
2008-03-13 13:06:53 +00:00
|
|
|
case Qt::ToolTipRole:
|
2007-09-09 16:15:33 +00:00
|
|
|
return item->text;
|
|
|
|
break;
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
if ( item->highlight )
|
2016-03-21 23:29:53 +00:00
|
|
|
{
|
2016-10-29 09:13:24 +00:00
|
|
|
const QVariant icon = QIcon::fromTheme( QApplication::layoutDirection() == Qt::RightToLeft ? QStringLiteral("arrow-left") : QStringLiteral("arrow-right") );
|
2016-03-21 23:29:53 +00:00
|
|
|
TOCItem *lastHighlighted = d->currentPage.last();
|
|
|
|
|
|
|
|
// in the mobile version our parent is not a QTreeView; add icon to the last highlighted item
|
|
|
|
// TODO misusing parent() here, fix
|
|
|
|
QTreeView *view = dynamic_cast< QTreeView* > ( QObject::parent() );
|
|
|
|
if ( !view )
|
|
|
|
{
|
|
|
|
if ( item == lastHighlighted )
|
|
|
|
return icon;
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( view->isExpanded( index ) )
|
|
|
|
{
|
|
|
|
// if this is the last highlighted node, its child is on a page below, thus it needs icon
|
|
|
|
if ( item == lastHighlighted )
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
}
|
2007-09-09 16:15:33 +00:00
|
|
|
break;
|
|
|
|
case PageItemDelegate::PageRole:
|
|
|
|
if ( item->viewport.isValid() )
|
|
|
|
return item->viewport.pageNumber + 1;
|
|
|
|
break;
|
|
|
|
case PageItemDelegate::PageLabelRole:
|
2011-02-12 14:42:55 +00:00
|
|
|
if ( item->viewport.isValid() && item->viewport.pageNumber < int(d->document->pages()) )
|
2007-09-09 16:15:33 +00:00
|
|
|
return d->document->page( item->viewport.pageNumber )->label();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TOCModel::hasChildren( const QModelIndex &parent ) const
|
|
|
|
{
|
|
|
|
if ( !parent.isValid() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( parent.internalPointer() );
|
|
|
|
return !item->children.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TOCModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
|
|
|
{
|
|
|
|
if ( orientation != Qt::Horizontal )
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if ( section == 0 && role == Qt::DisplayRole )
|
2016-07-11 20:05:18 +00:00
|
|
|
return QStringLiteral("Topics");
|
2007-09-09 16:15:33 +00:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex TOCModel::index( int row, int column, const QModelIndex &parent ) const
|
|
|
|
{
|
|
|
|
if ( row < 0 || column != 0 )
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
TOCItem *item = parent.isValid() ? static_cast< TOCItem* >( parent.internalPointer() ) : d->root;
|
|
|
|
if ( row < item->children.count() )
|
|
|
|
return createIndex( row, column, item->children.at( row ) );
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex TOCModel::parent( const QModelIndex &index ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QModelIndex();
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( index.internalPointer() );
|
|
|
|
return d->indexForItem( item->parent );
|
|
|
|
}
|
|
|
|
|
|
|
|
int TOCModel::rowCount( const QModelIndex &parent ) const
|
|
|
|
{
|
|
|
|
TOCItem *item = parent.isValid() ? static_cast< TOCItem* >( parent.internalPointer() ) : d->root;
|
|
|
|
return item->children.count();
|
|
|
|
}
|
|
|
|
|
2013-01-09 22:31:23 +00:00
|
|
|
static QModelIndex indexForIndex( const QModelIndex &oldModelIndex, QAbstractItemModel *newModel )
|
|
|
|
{
|
|
|
|
QModelIndex newModelIndex;
|
|
|
|
if ( oldModelIndex.parent().isValid() )
|
|
|
|
{
|
|
|
|
newModelIndex = newModel->index( oldModelIndex.row(), oldModelIndex.column(), indexForIndex( oldModelIndex.parent(), newModel ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newModelIndex = newModel->index( oldModelIndex.row(), oldModelIndex.column() );
|
|
|
|
}
|
|
|
|
return newModelIndex;
|
|
|
|
}
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
void TOCModel::fill( const Okular::DocumentSynopsis *toc )
|
|
|
|
{
|
2013-01-18 17:02:07 +00:00
|
|
|
if ( !toc )
|
2007-09-09 16:15:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
clear();
|
|
|
|
emit layoutAboutToBeChanged();
|
|
|
|
d->addChildren( *toc, d->root );
|
|
|
|
d->dirty = true;
|
|
|
|
emit layoutChanged();
|
2013-01-09 22:31:23 +00:00
|
|
|
if ( equals( d->m_oldModel ) )
|
2007-09-09 16:15:33 +00:00
|
|
|
{
|
2013-01-09 22:31:23 +00:00
|
|
|
foreach( const QModelIndex &oldIndex, d->m_oldTocExpandedIndexes )
|
|
|
|
{
|
|
|
|
const QModelIndex index = indexForIndex( oldIndex, this );
|
|
|
|
if ( !index.isValid() )
|
|
|
|
continue;
|
|
|
|
|
2016-03-21 23:29:53 +00:00
|
|
|
// TODO misusing parent() here, fix
|
2013-01-09 22:31:23 +00:00
|
|
|
QMetaObject::invokeMethod( QObject::parent(), "expand", Qt::QueuedConnection, Q_ARG( QModelIndex, index ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach ( TOCItem *item, d->itemsToOpen )
|
|
|
|
{
|
|
|
|
const QModelIndex index = d->indexForItem( item );
|
|
|
|
if ( !index.isValid() )
|
|
|
|
continue;
|
|
|
|
|
2016-03-21 23:29:53 +00:00
|
|
|
// TODO misusing parent() here, fix
|
2013-01-09 22:31:23 +00:00
|
|
|
QMetaObject::invokeMethod( QObject::parent(), "expand", Qt::QueuedConnection, Q_ARG( QModelIndex, index ) );
|
|
|
|
}
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
2007-09-16 15:00:40 +00:00
|
|
|
d->itemsToOpen.clear();
|
2013-01-09 22:31:23 +00:00
|
|
|
delete d->m_oldModel;
|
2017-09-05 21:27:18 +00:00
|
|
|
d->m_oldModel = nullptr;
|
2013-01-09 22:31:23 +00:00
|
|
|
d->m_oldTocExpandedIndexes.clear();
|
2007-09-09 16:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TOCModel::clear()
|
|
|
|
{
|
|
|
|
if ( !d->dirty )
|
|
|
|
return;
|
|
|
|
|
2016-07-24 21:46:53 +00:00
|
|
|
beginResetModel();
|
2007-09-09 16:15:33 +00:00
|
|
|
qDeleteAll( d->root->children );
|
|
|
|
d->root->children.clear();
|
|
|
|
d->currentPage.clear();
|
2016-07-24 21:46:53 +00:00
|
|
|
endResetModel();
|
2007-09-09 16:15:33 +00:00
|
|
|
d->dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TOCModel::setCurrentViewport( const Okular::DocumentViewport &viewport )
|
|
|
|
{
|
|
|
|
foreach ( TOCItem* item, d->currentPage )
|
|
|
|
{
|
|
|
|
QModelIndex index = d->indexForItem( item );
|
|
|
|
if ( !index.isValid() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
item->highlight = false;
|
|
|
|
emit dataChanged( index, index );
|
|
|
|
}
|
|
|
|
d->currentPage.clear();
|
|
|
|
|
|
|
|
QList< TOCItem* > newCurrentPage;
|
|
|
|
d->findViewport( viewport, d->root, newCurrentPage );
|
|
|
|
|
|
|
|
d->currentPage = newCurrentPage;
|
|
|
|
|
|
|
|
foreach ( TOCItem* item, d->currentPage )
|
|
|
|
{
|
|
|
|
QModelIndex index = d->indexForItem( item );
|
|
|
|
if ( !index.isValid() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
item->highlight = true;
|
|
|
|
emit dataChanged( index, index );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-26 16:01:54 +00:00
|
|
|
bool TOCModel::isEmpty() const
|
|
|
|
{
|
|
|
|
return d->root->children.isEmpty();
|
|
|
|
}
|
|
|
|
|
2013-01-09 22:31:23 +00:00
|
|
|
bool TOCModel::equals( const TOCModel *model ) const
|
|
|
|
{
|
|
|
|
if ( model )
|
|
|
|
return checkequality( model );
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TOCModel::setOldModelData( TOCModel *model, const QVector<QModelIndex> &list )
|
|
|
|
{
|
|
|
|
delete d->m_oldModel;
|
|
|
|
d->m_oldModel = model;
|
|
|
|
d->m_oldTocExpandedIndexes = list;
|
|
|
|
}
|
|
|
|
|
2013-06-02 13:55:49 +00:00
|
|
|
bool TOCModel::hasOldModelData() const
|
|
|
|
{
|
2017-09-05 21:27:18 +00:00
|
|
|
return (d->m_oldModel != nullptr);
|
2013-06-02 13:55:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 17:02:07 +00:00
|
|
|
TOCModel *TOCModel::clearOldModelData() const
|
|
|
|
{
|
|
|
|
TOCModel *oldModel = d->m_oldModel;
|
2017-09-05 21:27:18 +00:00
|
|
|
d->m_oldModel = nullptr;
|
2013-01-18 17:02:07 +00:00
|
|
|
d->m_oldTocExpandedIndexes.clear();
|
|
|
|
return oldModel;
|
|
|
|
}
|
|
|
|
|
2007-09-09 16:15:33 +00:00
|
|
|
QString TOCModel::externalFileNameForIndex( const QModelIndex &index ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( index.internalPointer() );
|
|
|
|
return item->extFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
Okular::DocumentViewport TOCModel::viewportForIndex( const QModelIndex &index ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return Okular::DocumentViewport();
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( index.internalPointer() );
|
|
|
|
return item->viewport;
|
|
|
|
}
|
|
|
|
|
2008-11-30 15:48:01 +00:00
|
|
|
QString TOCModel::urlForIndex( const QModelIndex &index ) const
|
|
|
|
{
|
|
|
|
if ( !index.isValid() )
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
TOCItem *item = static_cast< TOCItem* >( index.internalPointer() );
|
|
|
|
return item->url;
|
|
|
|
}
|
|
|
|
|
2013-01-09 22:31:23 +00:00
|
|
|
bool TOCModel::checkequality( const TOCModel *model, const QModelIndex & parentA, const QModelIndex & parentB ) const
|
|
|
|
{
|
|
|
|
if ( rowCount( parentA ) != model->rowCount( parentB ) )
|
|
|
|
return false;
|
|
|
|
for ( int i = 0; i < rowCount( parentA ); i++ )
|
|
|
|
{
|
|
|
|
QModelIndex indxA = index( i, 0, parentA );
|
|
|
|
QModelIndex indxB = model->index( i, 0, parentB );
|
|
|
|
if ( indxA.data() != indxB.data() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( hasChildren( indxA ) != model->hasChildren( indxB ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( !checkequality( model, indxA, indxB ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-08 22:00:07 +00:00
|
|
|
#include "moc_tocmodel.cpp"
|