~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to src/qgssvgcache.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
               qgssvgcache.h  -  SVG rendering and pixmap caching
3
 
                             -------------------
4
 
    begin                : Sat Jul 17 2004
5
 
    copyright            : (C) 2004 by Lars Luthman
6
 
    email                : larsl at users dot sourceforge dot org
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
/*  $Id: qgssvgcache.h,v 1.3 2005/04/02 09:44:11 rabla Exp $ */
18
 
 
19
 
#ifndef QGSSVGCACHE_H
20
 
#define QGSSVGCACHE_H
21
 
 
22
 
#include <map>
23
 
#include <queue>
24
 
 
25
 
#include <qpixmap.h>
26
 
#include <qpicture.h>
27
 
 
28
 
 
29
 
/** This class is a singleton that does all the SVG rendering in QGIS.
30
 
    When another part of the program needs to render an SVG file, it
31
 
    calls the getPixmap() function to get a pixmap rendering of that
32
 
    SVG file in the wanted scale. This class also does some extra 
33
 
    tricks to make Qt's SVG renderings look a little bit better, and
34
 
    it caches the pixmaps to speed things up.
35
 
*/
36
 
class QgsSVGCache {
37
 
 public:
38
 
  
39
 
  QgsSVGCache();
40
 
  
41
 
  /** This function returns a pixmap containing a rendering of the SVG file
42
 
      @c filename scaled by the factor @c scaleFactor. The pixmaps background
43
 
      will be transparent, and if the file for some reason can't be rendered
44
 
      the pixmap will be completely transparent. */
45
 
  QPixmap getPixmap(QString filename, double scaleFactor);
46
 
  
47
 
  /** Returns SVG picture in original size */
48
 
  QPicture getPicture(QString filename);
49
 
  
50
 
  /** This function clears the pixmap cache and forces all newly requested
51
 
      pixmaps to be rendered again. Can be useful if the oversampling factor
52
 
      has changed and you want to get rid of cached lower-quality pixmaps. */
53
 
  void clear();
54
 
  
55
 
  /** When a pixmap is requested and it is not in the cache, it will be 
56
 
      loaded using a QPicture and rendered to a QPixmap. Since Qt does not do
57
 
      any kind of anti-aliasing or smoothing, the QPicture is first rendered
58
 
      to a pixmap that is larger than the requested size, and then it's scaled
59
 
      down using QImage::smoothScale() to smooth out sharp edges and lines.
60
 
      The oversampling factor determins how much larger the first pixmap is -
61
 
      the larger this factor is the smoother the final pixmap will look, but
62
 
      it will also take longer time to render and scale the image. This
63
 
      function sets the oversampling factor. It should be larger than or equal
64
 
      to 1. 
65
 
  */
66
 
  void setOversampling(int oversamplingFactor);
67
 
  
68
 
  /** This function returns the oversampling factor.
69
 
      @see setOversampling()
70
 
  */
71
 
  int getOversampling() const;
72
 
  
73
 
  /** This function returns a reference to the singleton object. */
74
 
  static inline QgsSVGCache& instance();
75
 
  
76
 
 protected:
77
 
  
78
 
  typedef std::map<QString, QPicture> PictureMap;
79
 
  PictureMap pictureMap;
80
 
 
81
 
  typedef std::map<std::pair<QString, double>, QPixmap> PixmapMap;
82
 
  PixmapMap pixmapMap;
83
 
  int oversampling;
84
 
  std::queue<PixmapMap::key_type> fifo;
85
 
  int pixelLimit;
86
 
  int totalPixels;
87
 
  
88
 
};
89
 
 
90
 
 
91
 
QgsSVGCache& QgsSVGCache::instance() {
92
 
  static QgsSVGCache obj;
93
 
  return obj;
94
 
}
95
 
 
96
 
#endif