1
/***************************************************************************
5
copyright : (C) 2005 by Radim Blazek
7
***************************************************************************/
8
/***************************************************************************
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. *
15
***************************************************************************/
18
#include <qapplication.h>
21
#include <qfiledialog.h>
22
#include <qsettings.h>
25
#include <qstringlist.h>
27
#include <qcombobox.h>
29
#include <qmessagebox.h>
30
#include <qinputdialog.h>
31
#include <qsettings.h>
35
#include <qpointarray.h>
37
#include <qnamespace.h>
38
#include <qlistview.h>
39
#include <qcolordialog.h>
41
#include <qstatusbar.h>
46
#include <qtabwidget.h>
48
#include <qcheckbox.h>
52
#include "../../src/qgis.h"
53
#include "../../src/qgsmapcanvas.h"
54
#include "../../src/qgsmaplayer.h"
55
#include "../../src/qgsvectorlayer.h"
56
#include "../../src/qgsdataprovider.h"
57
#include "../../src/qgsfield.h"
58
#include "../../src/qgsfeatureattribute.h"
65
#include "../../providers/grass/qgsgrass.h"
66
#include "../../providers/grass/qgsgrassprovider.h"
67
#include "qgsgrassattributes.h"
68
#include "qgsgrasstools.h"
69
#include "qgsgrassmodule.h"
71
QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
72
QWidget * parent, const char * name, WFlags f )
73
:QgsGrassToolsBase ( parent, name, f )
76
std::cerr << "QgsGrassTools()" << std::endl;
81
mCanvas = mIface->getMapCanvas();
84
mModulesListView->setColumnText(0,"Modules");
85
mModulesListView->clear();
86
mModulesListView->setSorting(-1);
87
mModulesListView->setRootIsDecorated(true);
88
mModulesListView->setResizeMode(QListView::AllColumns);
89
mModulesListView->header()->hide();
91
connect( mModulesListView, SIGNAL(clicked(QListViewItem *)),
92
this, SLOT(moduleClicked( QListViewItem *)) );
94
#if defined(WIN32) || defined(Q_OS_MACX)
95
mAppDir = qApp->applicationDirPath();
100
QString conf = mAppDir + "/share/qgis/grass/config/default.qgc";
106
void QgsGrassTools::moduleClicked( QListViewItem * item )
110
QString name = item->text(1);
111
//std::cerr << "name = " << name << std::endl;
113
if ( name.length() == 0 ) return; // Section
115
QString path = mAppDir + "/share/qgis/grass/modules/" + name;
116
QgsGrassModule *m = new QgsGrassModule ( this, mQgisApp, mIface, path, mTabWidget );
117
//mTabWidget->addTab ( m, item->text(0) );
119
QPixmap pixmap = QgsGrassModule::pixmap ( path, 25 );
121
is.setPixmap ( pixmap, QIconSet::Small, QIconSet::Normal );
122
mTabWidget->addTab ( (QWidget*)m, is, "" );
124
mTabWidget->setCurrentPage ( mTabWidget->count()-1 );
127
bool QgsGrassTools::loadConfig(QString filePath)
130
std::cerr << "QgsGrassTools::loadConfig(): " << filePath << std::endl;
132
mModulesListView->clear();
134
QFile file ( filePath );
136
if ( !file.exists() ) {
137
QMessageBox::warning( 0, "Warning", "The config file (" + filePath + ") not found." );
140
if ( ! file.open( IO_ReadOnly ) ) {
141
QMessageBox::warning( 0, "Warning", "Cannot open config file (" + filePath + ")" );
145
QDomDocument doc ( "qgisgrass" );
148
if ( !doc.setContent( &file, &err, &line, &column ) ) {
149
QString errmsg = "Cannot read config file (" + filePath + "):\n" + err + "\nat line "
150
+ QString::number(line) + " column " + QString::number(column);
151
std::cerr << errmsg << std::endl;
152
QMessageBox::warning( 0, "Warning", errmsg );
157
QDomElement docElem = doc.documentElement();
158
QDomNodeList modulesNodes = docElem.elementsByTagName ( "modules" );
160
if ( modulesNodes.count() == 0 ) {
165
QDomNode modulesNode = modulesNodes.item(0);
166
QDomElement modulesElem = modulesNode.toElement();
168
// Go through the sections and modules and add them to the list view
169
addModules ( 0, modulesElem );
174
void QgsGrassTools::addModules ( QListViewItem *parent, QDomElement &element )
176
QDomNode n = element.firstChild();
179
QListViewItem *lastItem = 0;
180
while( !n.isNull() ) {
181
QDomElement e = n.toElement();
183
//std::cout << "tag = " << e.tagName() << std::endl;
185
if ( e.tagName() == "section" && e.tagName() == "grass" ) {
186
std::cout << "Unknown tag: " << e.tagName() << std::endl;
191
item = new QListViewItem( parent, lastItem );
193
item = new QListViewItem( mModulesListView, lastItem );
196
if ( e.tagName() == "section" ) {
197
QString label = e.attribute("label");
198
std::cout << "label = " << label << std::endl;
199
item->setText( 0, label );
200
item->setOpen(true); // for debuging to spare one click
202
addModules ( item, e );
205
} else if ( e.tagName() == "grass" ) { // GRASS module
206
QString name = e.attribute("name");
207
std::cout << "name = " << name << std::endl;
209
QString path = mAppDir + "/share/qgis/grass/modules/" + name;
210
QString label = QgsGrassModule::label ( path );
211
QPixmap pixmap = QgsGrassModule::pixmap ( path, 25 );
213
item->setText( 0, label );
214
item->setPixmap( 0, pixmap );
215
item->setText( 1, name );
223
QgsGrassTools::~QgsGrassTools()
226
std::cerr << "QgsGrassTools::~QgsGrassTools()" << std::endl;
228
saveWindowLocation();
231
QString QgsGrassTools::appDir(void)
236
void QgsGrassTools::close(void)
238
saveWindowLocation();
242
void QgsGrassTools::closeEvent(QCloseEvent *e)
244
saveWindowLocation();
248
void QgsGrassTools::restorePosition()
251
int ww = settings.readNumEntry("/qgis/grass/windows/tools/w", 250);
252
int wh = settings.readNumEntry("/qgis/grass/windows/tools/h", 300);
253
int wx = settings.readNumEntry("/qgis/grass/windows/tools/x", 100);
254
int wy = settings.readNumEntry("/qgis/grass/windows/tools/y", 100);
257
QgsGrassToolsBase::show();
260
void QgsGrassTools::saveWindowLocation()
263
QPoint p = this->pos();
264
QSize s = this->size();
265
settings.writeEntry("/qgis/grass/windows/tools/x", p.x());
266
settings.writeEntry("/qgis/grass/windows/tools/y", p.y());
267
settings.writeEntry("/qgis/grass/windows/tools/w", s.width());
268
settings.writeEntry("/qgis/grass/windows/tools/h", s.height());