backport fixes for bookmarks sorting:

- r1129505, maintain the bookmark view sorted when adding new elements in the "selective" tree update
- r1129512, make sure actionsForUrl() returns actions sorted by page number

BUG: 205952
FIXED-IN: 4.4.4

svn path=/branches/KDE/4.4/kdegraphics/okular/; revision=1129515
remotes/origin/KDE/4.4
Pino Toscano 16 years ago
parent 0e833016e6
commit 314ea78655
  1. 16
      core/bookmarkmanager.cpp
  2. 10
      ui/bookmarklist.cpp

@ -37,12 +37,27 @@ class OkularBookmarkAction : public KBookmarkAction
public:
OkularBookmarkAction( const Okular::DocumentViewport& vp, const KBookmark& bk, KBookmarkOwner* owner, QObject *parent )
: KBookmarkAction( bk, owner, parent )
, m_pageNumber( vp.pageNumber + 1 )
{
if ( vp.isValid() )
setText( QString::number( vp.pageNumber + 1 ) + " - " + text() );
}
inline int pageNumber() const
{
return m_pageNumber;
}
private:
const int m_pageNumber;
};
inline bool okularBookmarkActionLessThan( QAction * a1, QAction * a2 )
{
return static_cast< OkularBookmarkAction * >( a1 )->pageNumber()
< static_cast< OkularBookmarkAction * >( a2 )->pageNumber();
}
class BookmarkManager::Private : public KBookmarkOwner
{
public:
@ -356,6 +371,7 @@ QList< QAction * > BookmarkManager::actionsForUrl( const KUrl& url ) const
}
break;
}
qSort( ret.begin(), ret.end(), okularBookmarkActionLessThan );
return ret;
}

@ -351,6 +351,8 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item )
else
{
const QString fileString = url.isLocalFile() ? url.path() : url.prettyUrl();
bool fileitem_created = false;
if ( item )
{
for ( int i = item->childCount() - 1; i >= 0; --i )
@ -363,6 +365,7 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item )
item = new QTreeWidgetItem( m_tree, FileItemType );
item->setText( 0, fileString );
item->setData( 0, UrlRole, qVariantFromValue( url ) );
fileitem_created = true;
}
if ( m_document->isOpened() && url == m_document->currentDocument() )
{
@ -374,6 +377,13 @@ void BookmarkList::selectiveUrlUpdate( const KUrl& url, QTreeWidgetItem*& item )
{
item->setToolTip( 0, i18ncp( "%1 is the file name", "%1\n\nOne bookmark", "%1\n\n%2 bookmarks", fileString, item->childCount() ) );
}
if ( fileitem_created )
{
// we need to sort also the parent of the new file item,
// so it can be properly shown in the correct place
m_tree->invisibleRootItem()->sortChildren( 0, Qt::AscendingOrder );
}
item->sortChildren( 0, Qt::AscendingOrder );
}
connect( m_tree, SIGNAL( itemChanged( QTreeWidgetItem *, int ) ), this, SLOT( slotChanged( QTreeWidgetItem * ) ) );

Loading…
Cancel
Save