Skip to content

Commit 0651c53

Browse files
author
rblazek
committed
data browser
git-svn-id: http://svn.osgeo.org/qgis/trunk@4915 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 553bedf commit 0651c53

File tree

6 files changed

+1062
-1
lines changed

6 files changed

+1062
-1
lines changed

src/plugins/grass/Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ plugin_LTLIBRARIES = grassplugin.la
3535

3636
plugin_MOC = qgsgrassplugin.moc.cpp \
3737
qgsgrassselect.moc.cpp \
38+
qgsgrassbrowser.moc.cpp \
3839
qgsgrassedit.moc.cpp \
3940
qgsgrasstools.moc.cpp \
41+
qgsgrassmodel.moc.cpp \
4042
qgsgrassmapcalc.moc.cpp \
4143
qgsgrassmodule.moc.cpp \
4244
qgsgrassnewmapset.moc.cpp \
@@ -68,10 +70,14 @@ grassplugin_la_SOURCES = qgsgrassplugin.cpp \
6870
qgsgrassplugin.h \
6971
qgsgrassselect.cpp \
7072
qgsgrassselect.h \
73+
qgsgrassbrowser.cpp \
74+
qgsgrassbrowser.h \
7175
qgsgrassedit.cpp \
7276
qgsgrassedit.h \
7377
qgsgrasstools.cpp \
7478
qgsgrasstools.h \
79+
qgsgrassmodel.cpp \
80+
qgsgrassmodel.h \
7581
qgsgrassmapcalc.cpp \
7682
qgsgrassmapcalc.h \
7783
qgsgrassmodule.cpp \

src/plugins/grass/qgsgrassbrowser.cpp

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*******************************************************************
2+
qgsgrassbrowser.cpp
3+
-------------------
4+
begin : February, 2006
5+
copyright : (C) 2006 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
********************************************************************/
8+
/********************************************************************
9+
This program is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or
12+
(at your option) any later version.
13+
*******************************************************************/
14+
#include <iostream>
15+
#include <vector>
16+
17+
#include <QApplication>
18+
#include <QStyle>
19+
#include <qdir.h>
20+
#include <qfile.h>
21+
#include <qsettings.h>
22+
#include <qstringlist.h>
23+
#include <qmessagebox.h>
24+
#include <qpainter.h>
25+
#include <qpixmap.h>
26+
#include <qnamespace.h>
27+
#include <qevent.h>
28+
#include <qsize.h>
29+
#include <qicon.h>
30+
#include <QTreeView>
31+
#include <QHeaderView>
32+
#include <QMainWindow>
33+
#include <QActionGroup>
34+
#include <QToolBar>
35+
#include <QAction>
36+
#include <QTextBrowser>
37+
#include <QSplitter>
38+
39+
#include "qgis.h"
40+
#include "qgsapplication.h"
41+
42+
extern "C" {
43+
#include <grass/gis.h>
44+
#include <grass/Vect.h>
45+
}
46+
47+
#include "../../src/providers/grass/qgsgrass.h"
48+
#include "qgsgrassmodel.h"
49+
#include "qgsgrassbrowser.h"
50+
51+
QgsGrassBrowser::QgsGrassBrowser ( QgisIface *iface,
52+
QWidget * parent, Qt::WFlags f )
53+
:mIface(iface), QMainWindow(parent, Qt::WType_Dialog)
54+
{
55+
#ifdef QGISDEBUG
56+
std::cerr << "QgsGrassBrowser()" << std::endl;
57+
#endif
58+
59+
QActionGroup *ag = new QActionGroup ( this );
60+
QToolBar *tb = addToolBar(tr("Tools"));
61+
62+
QString myIconPath = QgsApplication::themePath() + "/grass/";
63+
mActionAddMap = new QAction(
64+
QIcon(myIconPath+"grass_add_map.png"),
65+
tr("Add selected map to canvas"), this);
66+
mActionAddMap->setEnabled(false);
67+
ag->addAction ( mActionAddMap );
68+
tb->addAction ( mActionAddMap );
69+
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );
70+
71+
mActionRefresh = new QAction(
72+
QIcon(myIconPath+"grass_refresh.png"),
73+
tr("Refresh"), this);
74+
ag->addAction ( mActionRefresh );
75+
tb->addAction ( mActionRefresh );
76+
connect ( mActionRefresh, SIGNAL(triggered()), this, SLOT(refresh()) );
77+
78+
// Add model
79+
mModel = new QgsGrassModel ( this );
80+
81+
mTree = new QTreeView(0);
82+
mTree->header()->hide();
83+
mTree->setModel(mModel);
84+
85+
mTextBrowser = new QTextBrowser(0);
86+
mTextBrowser->setTextFormat(Qt::RichText);
87+
mTextBrowser->setReadOnly(TRUE);
88+
89+
mSplitter = new QSplitter(0);
90+
mSplitter->addWidget(mTree);
91+
mSplitter->addWidget(mTextBrowser);
92+
93+
this->setCentralWidget(mSplitter);
94+
95+
connect ( mTree->selectionModel(),
96+
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
97+
this, SLOT(selectionChanged(QItemSelection,QItemSelection)) );
98+
99+
connect ( mTree->selectionModel(),
100+
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
101+
this, SLOT(currentChanged(QModelIndex,QModelIndex)) );
102+
}
103+
104+
QgsGrassBrowser::~QgsGrassBrowser() { }
105+
106+
void QgsGrassBrowser::refresh()
107+
{
108+
#ifdef QGISDEBUG
109+
std::cerr << "QgsGrassBrowser::refresh()" << std::endl;
110+
#endif
111+
112+
mModel->refresh();
113+
mTree->update();
114+
}
115+
116+
void QgsGrassBrowser::addMap()
117+
{
118+
#ifdef QGISDEBUG
119+
std::cerr << "QgsGrassBrowser::addMap()" << std::endl;
120+
#endif
121+
122+
QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
123+
bool mapSelected = false;
124+
125+
QList<QModelIndex>::const_iterator it = indexes.begin();
126+
for (; it != indexes.end(); ++it)
127+
{
128+
int type = mModel->itemType(*it);
129+
QString uri = mModel->uri(*it);
130+
if ( type == QgsGrassModel::Raster )
131+
{
132+
std::cerr << "add raster: " << uri.ascii() << std::endl;
133+
mIface->addRasterLayer( uri );
134+
mapSelected = true;
135+
}
136+
else if ( type == QgsGrassModel::VectorLayer )
137+
{
138+
// TODO: common method for vector names
139+
QStringList split = QStringList::split ( '/', uri );
140+
QString layer = split.last();
141+
split.pop_back(); // map
142+
QString vector = split.last();
143+
mIface->addVectorLayer( uri, layer, "grass");
144+
std::cerr << "add vector: " << uri.ascii() << std::endl;
145+
mapSelected = true;
146+
}
147+
}
148+
}
149+
150+
void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
151+
{
152+
#ifdef QGISDEBUG
153+
std::cerr << "QgsGrassBrowser::selectionChanged()" << std::endl;
154+
#endif
155+
156+
mActionAddMap->setEnabled(false);
157+
158+
QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
159+
160+
mTextBrowser->clear();
161+
162+
QList<QModelIndex>::const_iterator it = indexes.begin();
163+
for (; it != indexes.end(); ++it)
164+
{
165+
mTextBrowser->append ( mModel->itemInfo(*it) );
166+
167+
int type = mModel->itemType(*it);
168+
if ( type == QgsGrassModel::Raster || type == QgsGrassModel::VectorLayer )
169+
{
170+
mActionAddMap->setEnabled(true);
171+
}
172+
}
173+
174+
}
175+
176+
void QgsGrassBrowser::currentChanged(const QModelIndex & current, const QModelIndex & previous)
177+
{
178+
#ifdef QGISDEBUG
179+
std::cerr << "QgsGrassBrowser::currentChanged()" << std::endl;
180+
#endif
181+
}
182+

src/plugins/grass/qgsgrassbrowser.h

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
qgsgrasstree.h
3+
-------------------
4+
begin : February, 2006
5+
copyright : (C) 2006 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSGRASSBROWSER_H
17+
#define QGSGRASSBROWSER_H
18+
19+
#include <QMainWindow>
20+
class QSplitter;
21+
class QAction;
22+
class QTreeView;
23+
class QTextBrowser;
24+
class QDirModel;
25+
26+
#include "qgisiface.h"
27+
#include "qgsgrassmodel.h"
28+
29+
/*! \class QgsGrassBrowser
30+
* \brief Model representing GRASS location structure.
31+
*/
32+
class QgsGrassBrowser: public QMainWindow
33+
{
34+
Q_OBJECT;
35+
36+
public:
37+
//! Constructor
38+
QgsGrassBrowser ( QgisIface *iface, QWidget * parent = 0, Qt::WFlags f = 0 );
39+
40+
//! Destructor
41+
~QgsGrassBrowser();
42+
43+
public slots:
44+
// Add selected map to canvas
45+
void addMap();
46+
47+
// Refresh model
48+
void refresh();
49+
50+
// Called when tree selection changes
51+
void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
52+
void currentChanged(const QModelIndex & current, const QModelIndex & previous);
53+
54+
private:
55+
QgisIface *mIface;
56+
57+
//! Current GISBASE
58+
QString mGisbase;
59+
60+
//! Current LOCATION_NAME
61+
QString mLocation;
62+
63+
// ! Data model
64+
QgsGrassModel *mModel;
65+
66+
QSplitter *mSplitter;
67+
68+
QTreeView *mTree;
69+
70+
QTextBrowser *mTextBrowser;
71+
72+
//! Actions
73+
QAction *mActionAddMap;
74+
QAction *mActionRefresh;
75+
};
76+
77+
#endif // QGSGRASSBROWSER_H

0 commit comments

Comments
 (0)