Start a View class for managing the "views" of a document.

Provide ways to register & unregister the view from a Document, and to get/set the view capabilities.

svn path=/trunk/KDE/kdegraphics/okular/; revision=801657
remotes/origin/KDE/4.1
Pino Toscano 18 years ago
parent 1ed3928811
commit 5851ddf6a8
  1. 1
      CMakeLists.txt
  2. 41
      core/document.cpp
  3. 17
      core/document.h
  4. 3
      core/document_p.h
  5. 77
      core/view.cpp
  6. 111
      core/view.h
  7. 33
      core/view_p.h

@ -44,6 +44,7 @@ set(okularcore_SRCS
core/textdocumentgenerator.cpp
core/textpage.cpp
core/utils.cpp
core/view.cpp
core/fileprinter.cpp
)

@ -65,6 +65,8 @@
#include "scripter.h"
#include "settings.h"
#include "sourcereference.h"
#include "view.h"
#include "view_p.h"
#include <config-okular.h>
@ -1209,6 +1211,13 @@ Document::~Document()
// delete generator, pages, and related stuff
closeDocument();
QSet< View * >::const_iterator viewIt = d->m_views.begin(), viewEnd = d->m_views.end();
for ( ; viewIt != viewEnd; ++viewIt )
{
View *v = *viewIt;
v->d_func()->document = 0;
}
// delete the bookmark manager
delete d->m_bookmarkManager;
@ -2852,6 +2861,38 @@ bool Document::saveChanges( const QString &fileName )
return saveIface->save( fileName, SaveInterface::SaveChanges );
}
void Document::registerView( View *view )
{
if ( !view )
return;
Document *viewDoc = view->viewDocument();
if ( viewDoc )
{
// check if already registered for this document
if ( viewDoc == this )
return;
viewDoc->unregisterView( view );
}
d->m_views.insert( view );
view->d_func()->document = d;
}
void Document::unregisterView( View *view )
{
if ( !view )
return;
Document *viewDoc = view->viewDocument();
if ( !viewDoc || viewDoc != this )
return;
view->d_func()->document = 0;
d->m_views.remove( view );
}
void DocumentPrivate::requestDone( PixmapRequest * req )
{
if ( !req )

@ -48,6 +48,7 @@ class Action;
class Page;
class PixmapRequest;
class SourceReference;
class View;
class VisiblePageRect;
/** IDs for seaches. Globally defined here. **/
@ -534,6 +535,22 @@ class OKULAR_EXPORT Document : public QObject
*/
bool saveChanges( const QString &fileName );
/**
* Register the specified @p view for the current document.
*
* It is unregistered from the previous document, if any.
*
* @since 0.7 (KDE 4.1)
*/
void registerView( View *view );
/**
* Unregister the specified @p view from the current document.
*
* @since 0.7 (KDE 4.1)
*/
void unregisterView( View *view );
public Q_SLOTS:
/**
* This slot is called whenever the user changes the @p rotation of

@ -37,6 +37,7 @@ namespace Okular {
class ConfigInterface;
class SaveInterface;
class Scripter;
class View;
}
struct GeneratorInfo
@ -196,6 +197,8 @@ class DocumentPrivate
QPointer< FontExtractionThread > m_fontThread;
bool m_fontsCached;
FontInfo::List m_fontsCache;
QSet< View * > m_views;
};
}

@ -0,0 +1,77 @@
/***************************************************************************
* Copyright (C) 2008 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 "view.h"
#include "view_p.h"
// local includes
#include "document_p.h"
using namespace Okular;
ViewPrivate::ViewPrivate()
: document( 0 )
{
}
ViewPrivate::~ViewPrivate()
{
}
View::View( const QString &name )
: d_ptr( new ViewPrivate() )
{
d_ptr->name = name;
}
View::~View()
{
if ( d_ptr->document )
{
d_ptr->document->m_views.remove( this );
}
delete d_ptr;
}
Document* View::viewDocument() const
{
return d_ptr->document ? d_ptr->document->m_parent : 0;
}
QString View::name() const
{
return d_ptr->name;
}
bool View::supportsCapability( View::ViewCapability capability ) const
{
Q_UNUSED( capability )
return false;
}
View::CapabilityFlags View::capabilityFlags( View::ViewCapability capability ) const
{
Q_UNUSED( capability )
return 0;
}
QVariant View::capability( View::ViewCapability capability ) const
{
Q_UNUSED( capability )
return QVariant();
}
void View::setCapability( View::ViewCapability capability, const QVariant &option )
{
Q_UNUSED( capability )
Q_UNUSED( option )
}

@ -0,0 +1,111 @@
/***************************************************************************
* Copyright (C) 2008 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. *
***************************************************************************/
#ifndef OKULAR_VIEW_H
#define OKULAR_VIEW_H
#include "okular_export.h"
class QString;
class QVariant;
namespace Okular {
class Document;
class DocumentPrivate;
class ViewPrivate;
/**
* @short View on the document
*
* The View class represents a "view" on a document.
* A view can be registered with only a document at a time.
*
* @since 0.7 (KDE 4.1)
*/
class OKULAR_EXPORT View
{
/// @cond PRIVATE
friend class Document;
friend class DocumentPrivate;
/// @endcond
public:
/**
* The capabilities of a view
*/
enum ViewCapability
{
Zoom ///< Possibility to get/set the zoom of the view
};
/**
* The access type of a capability
*/
enum CapabilityFlag
{
NoFlag = 0,
CapabilityRead = 0x01, ///< Possibility to read a capability
CapabilityWrite = 0x02 ///< Possibility to write a capability
};
Q_DECLARE_FLAGS( CapabilityFlags, CapabilityFlag )
virtual ~View();
/**
* Return the document which this view is associated to,
* or null if it is not associated with any document.
*/
Document* viewDocument() const;
/**
* Return the name of this view.
*/
QString name() const;
/**
* Query whether the view support the specified @p capability.
*/
virtual bool supportsCapability( ViewCapability capability ) const;
/**
* Query the flags for the specified @p capability.
*/
virtual CapabilityFlags capabilityFlags( ViewCapability capability ) const;
/**
* Query the value of the specified @p capability.
*/
virtual QVariant capability( ViewCapability capability ) const;
/**
* Sets a new value for the specified @p capability.
*/
virtual void setCapability( ViewCapability capability, const QVariant &option );
protected:
/**
* Construct a new view with the specified @p name.
*/
View( const QString &name );
/// @cond PRIVATE
Q_DECLARE_PRIVATE( View )
ViewPrivate *d_ptr;
/// @endcond
private:
Q_DISABLE_COPY( View )
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS( Okular::View::CapabilityFlags )
#endif

@ -0,0 +1,33 @@
/***************************************************************************
* Copyright (C) 2008 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. *
***************************************************************************/
#ifndef OKULAR_VIEW_P_H
#define OKULAR_VIEW_P_H
#include <QtCore/QHash>
#include <QtCore/QString>
namespace Okular {
class DocumentPrivate;
class View;
class ViewPrivate
{
public:
ViewPrivate();
virtual ~ViewPrivate();
QString name;
DocumentPrivate *document;
};
}
#endif
Loading…
Cancel
Save