mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
primitive legend implementation
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@88 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
7bc3e8f23f
commit
abaae24c55
@ -22,6 +22,7 @@
|
||||
#include <qstringlist.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qstatusbar.h>
|
||||
#include <qlabel.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qpixmap.h>
|
||||
@ -33,6 +34,7 @@
|
||||
#include <qwmatrix.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qvbox.h>
|
||||
#include <qlistview.h>
|
||||
#include <libpq++.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
@ -56,7 +58,13 @@ QgisApp::QgisApp (QWidget * parent, const char *name,
|
||||
QGridLayout *FrameLayout =
|
||||
new QGridLayout (frameMain, 1, 2, 4, 6, "mainFrameLayout");
|
||||
QSplitter *split = new QSplitter (frameMain);
|
||||
mapLegend = new QgsLegend (split); //frameMain);
|
||||
lv = new QListView(split);
|
||||
lv->addColumn("Layers");
|
||||
lv->setSorting(-1);
|
||||
|
||||
|
||||
mapLegend = new QgsLegend(lv); //frameMain);
|
||||
// mL = new QScrollView(split);
|
||||
//add a canvas
|
||||
mapCanvas = new QgsMapCanvas (split);
|
||||
// resize it to fit in the frame
|
||||
@ -67,6 +75,7 @@ QgisApp::QgisApp (QWidget * parent, const char *name,
|
||||
FrameLayout->addWidget (split, 0, 0);
|
||||
mapLegend->setBackgroundColor (QColor (192, 192, 192));
|
||||
mapLegend->setMapCanvas(mapCanvas);
|
||||
lv->setResizeMode(QListView::AllColumns);
|
||||
|
||||
|
||||
connect (mapCanvas, SIGNAL (xyCoordinates (QgsPoint &)), this,
|
||||
|
@ -21,9 +21,11 @@ class QCanvas;
|
||||
class QRect;
|
||||
class QCanvasView;
|
||||
class QStringList;
|
||||
class QScrollView;
|
||||
class QgsPoint;
|
||||
class QgsLegend;
|
||||
class QVBox;
|
||||
class QListView;
|
||||
#include "qgisappbase.h"
|
||||
|
||||
class QgsMapCanvas;
|
||||
@ -66,13 +68,14 @@ private:
|
||||
QgsMapCanvas *mapCanvas;
|
||||
//! Table of contents (legend) for the map
|
||||
QgsLegend *mapLegend;
|
||||
QScrollView *mL;
|
||||
//! scale factor
|
||||
double scaleFactor;
|
||||
//! Current map window extent in real-world coordinates
|
||||
QRect *mapWindow;
|
||||
//! Current map tool
|
||||
int mapTool;
|
||||
|
||||
QListView *lv;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,63 +18,42 @@
|
||||
#include <map>
|
||||
#include <qstring.h>
|
||||
#include <qpainter.h>
|
||||
#include <qlabel.h>
|
||||
#include <qvbox.h>
|
||||
#include <qlistview.h>
|
||||
#include "qgsmapcanvas.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include "qgslegenditem.h"
|
||||
#include "qgslegend.h"
|
||||
|
||||
QgsLegend::QgsLegend (QWidget * parent, const char *name):QScrollView (parent,
|
||||
name)
|
||||
QgsLegend::QgsLegend (QListView *lv, QWidget * parent, const char *name):QWidget (parent,
|
||||
name), listView(lv)
|
||||
{
|
||||
//legendContainer = new QVBox(viewport());
|
||||
// addChild(legendContainer);
|
||||
|
||||
}
|
||||
|
||||
QgsLegend::~QgsLegend ()
|
||||
{
|
||||
}
|
||||
|
||||
void QgsLegend::drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph){
|
||||
// Calculate the coordinates...
|
||||
int x1 = 0;
|
||||
int y1 = 0;
|
||||
int x2 = width();
|
||||
int y2 = height();//map->layerCount() * 35;
|
||||
|
||||
// Clip the coordinates so X/Windows will not have problems...
|
||||
if (x1 < clipx) x1=clipx;
|
||||
if (y1 < clipy) y1=clipy;
|
||||
if (x2 > clipx+clipw-1) x2=clipx+clipw-1;
|
||||
if (y2 > clipy+cliph-1) y2=clipy+cliph-1;
|
||||
|
||||
// Paint using the small coordinates...
|
||||
if ( x2 >= x1 && y2 >= y1 )
|
||||
p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red);
|
||||
|
||||
|
||||
}
|
||||
void QgsLegend::setMapCanvas(QgsMapCanvas *canvas){
|
||||
map = canvas;
|
||||
}
|
||||
|
||||
void QgsLegend::update(){
|
||||
resizeContents(width(),height());
|
||||
QPainter *p = new QPainter(this);
|
||||
drawContents(p, 0,0,width(),height());
|
||||
enableClipper(true);
|
||||
|
||||
// clear the legend
|
||||
|
||||
listView->clear();
|
||||
|
||||
// Get the list of layers in order from the
|
||||
// map canvas and add legenditems to the legend
|
||||
|
||||
|
||||
for(int idx=0; idx < map->layerCount(); idx++){
|
||||
QgsMapLayer *lyr = map->getZpos(idx);
|
||||
QgsLegendItem *li = new QgsLegendItem(lyr, this);
|
||||
addChild(li,0,idx*60);
|
||||
repaint();
|
||||
QListViewItem *lvi = new QListViewItem(listView, lyr->name());
|
||||
// QgsLegendItem *li = new QgsLegendItem(lyr, legendContainer);
|
||||
//addChild(li,0,idx*60);
|
||||
int foo = 1;
|
||||
//repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,28 +18,28 @@
|
||||
|
||||
#ifndef QGSLEGEND_H
|
||||
#define QGSLEGEND_H
|
||||
#include <qscrollview.h>
|
||||
#include <qwidget.h>
|
||||
class QgsMapCanvas;
|
||||
class QVBox;
|
||||
class QListView;
|
||||
|
||||
class QPainter;
|
||||
/**
|
||||
*@author Gary E.Sherman
|
||||
*/
|
||||
|
||||
class QgsLegend : public QScrollView{
|
||||
class QgsLegend : public QWidget{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsLegend(QWidget *parent=0, const char *name=0);
|
||||
QgsLegend(QListView *lv, QWidget *parent=0, const char *name=0);
|
||||
~QgsLegend();
|
||||
//! Set the pointer to the map canvas
|
||||
void setMapCanvas(QgsMapCanvas *canvas);
|
||||
//! Update the legend
|
||||
void update();
|
||||
void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
|
||||
|
||||
private:
|
||||
QListView* listView;
|
||||
QgsMapCanvas *map;
|
||||
// child of legend control that contains the legenditems
|
||||
QVBox *legendContainer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -116,6 +116,7 @@ void QgsMapCanvas::render2 ()
|
||||
{
|
||||
QgsMapLayer *ml = (*mi).second;
|
||||
// QgsDatabaseLayer *dbl = (QgsDatabaseLayer *)&ml;
|
||||
std::cout << "Rendering " << ml->name() << std::endl;
|
||||
ml->draw (paint, ¤tExtent, coordXForm);
|
||||
mi++;
|
||||
// mi.draw(p, &fullExtent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user