Skip to content

File tree

10 files changed

+114
-24
lines changed

10 files changed

+114
-24
lines changed
 

‎src/plugins/grass/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ SUBDIRS = config modules themes
1414

1515
INCLUDES = -I../../gui -I../../core
1616

17-
DEFS=-DGRASS_BASE=\"$(GRASS_BASE)\" -DHAVE_OPENPTY=$(HAVE_OPENPTY)
17+
DEFS=-DGRASS_BASE=\"$(GRASS_BASE)\" -DHAVE_OPENPTY=$(HAVE_OPENPTY)
18+
1819
if !HAVE_QTMAC
1920
PREFIX=-DPREFIX=\"$(prefix)\"
2021
endif

‎src/plugins/grass/Makefile.win

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
QGTOP=../../../
2+
3+
LDADD = ../../providers/grass/.libs/libqgisgrass.a $(PLUGIN_LIBS) $(GRASS_LIB)
4+
5+
OBJECTS = $(wildcard *.o)
6+
7+
PLUGIN = .libs/grassplugin.dll
8+
9+
all: objects $(PLUGIN)
10+
11+
objects:
12+
$(MAKE) -f Makefile
13+
14+
$(PLUGIN): $(OBJECTS)
15+
$(CXX) -shared -o $@ $(OBJECTS) $(LDADD)
16+
$(STRIP) $@
17+
18+
install: all
19+
$(INSTALL) -m 755 $(PLUGIN) $(prefix)/lib/qgis/grassplugin.dll
20+
21+
include ../../../Makefile.win.rules

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include <QGridLayout>
6464

6565
#include "qgis.h"
66+
#include "qgsapplication.h"
6667
#include "qgsmapcanvas.h"
6768
#include "qgsmaplayer.h"
6869
#include "qgsvectorlayer.h"
@@ -93,12 +94,15 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
9394
std::cerr << "QgsGrassModule()" << std::endl;
9495
#endif
9596

97+
setupUi(this);
98+
9699
mPath = path;
97100
mTools = tools;
98101
mQgisApp = qgisApp;
99102
mIface = iface;
100103
mCanvas = mIface->getMapCanvas();
101104
mParent = parent;
105+
//mAppDir = QgsApplication::applicationDirPath();
102106
mAppDir = mTools->appDir();
103107

104108
/* Read module description and create options */
@@ -187,8 +191,8 @@ QgsGrassModuleOptions::QgsGrassModuleOptions (
187191
mQgisApp = qgisApp;
188192
mIface = iface;
189193
mCanvas = mIface->getMapCanvas();
194+
//mAppDir = QgsApplication::applicationDirPath();
190195
mAppDir = mTools->appDir();
191-
192196
}
193197

194198
QgsGrassModuleOptions::~QgsGrassModuleOptions()
@@ -212,6 +216,7 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
212216
{
213217
#ifdef QGISDEBUG
214218
std::cerr << "QgsGrassModuleStandardOptions()" << std::endl;
219+
std::cerr << "PATH = " << getenv ("PATH") << std::endl;
215220
#endif
216221

217222
mXName = xname;
@@ -221,6 +226,11 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
221226
process->addArgument( mXName );
222227
process->addArgument( "--interface-description" );
223228

229+
// Attention: if a binary has the .exe extention it must be
230+
// also in mXName but we cannot append it here because
231+
// the modules can also be a script => ???
232+
// For now create in GISBASE/bin copy of each module without
233+
// .exe extension
224234
if ( !process->start( ) ) {
225235
QMessageBox::warning( 0, "Warning", "Cannot start module " + mXName );
226236
return;
@@ -1046,8 +1056,12 @@ void QgsGrassModuleInput::updateQgisLayers()
10461056
for ( int i = 0; i < nlayers; i++ ) {
10471057
QgsMapLayer *layer = canvas->getZpos(i);
10481058

1059+
#ifdef QGISDEBUG
1060+
std::cerr << "layer->type() = " << layer->type() << std::endl;
1061+
#endif
10491062
if ( mType == Vector && layer->type() == QgsMapLayer::VECTOR ) {
10501063
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
1064+
std::cerr << "vector->providerType() = " << vector->providerType().ascii() << std::endl;
10511065
if ( vector->providerType() != "grass" ) continue;
10521066

10531067
//TODO dynamic_cast ?
@@ -1065,9 +1079,14 @@ void QgsGrassModuleInput::updateQgisLayers()
10651079
}
10661080

10671081
// TODO add map() mapset() location() gisbase() to grass provider
1068-
QString source = QDir::cleanDirPath ( provider->getDataSourceUri() );
1069-
1070-
QChar sep = QDir::separator();
1082+
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
1083+
#ifdef QGISDEBUG
1084+
std::cerr << "source = " << source.ascii() << std::endl;
1085+
#endif
1086+
1087+
// Note: QDir::cleanPath is using '/' also on Windows
1088+
//QChar sep = QDir::separator();
1089+
QChar sep = '/';
10711090

10721091
// Check GISBASE and LOCATION
10731092
QStringList split = QStringList::split ( sep, source );
@@ -1081,12 +1100,20 @@ void QgsGrassModuleInput::updateQgisLayers()
10811100
QString mapset = split.last();
10821101
split.pop_back(); // mapset
10831102

1084-
QDir locDir ( sep + split.join ( QString(sep) ) ) ;
1085-
QString loc = locDir.canonicalPath();
1103+
//QDir locDir ( sep + split.join ( QString(sep) ) ) ;
1104+
//QString loc = locDir.canonicalPath();
1105+
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
10861106

10871107
QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
10881108
QString curloc = curlocDir.canonicalPath();
10891109

1110+
#ifdef QGISDEBUG
1111+
std::cerr << "loc = " << loc.ascii() << std::endl;
1112+
std::cerr << "curloc = " << curloc.ascii() << std::endl;
1113+
std::cerr << "mapset = " << mapset.ascii() << std::endl;
1114+
std::cerr << "QgsGrass::getDefaultMapset() = " << QgsGrass::getDefaultMapset().ascii() << std::endl;
1115+
#endif
1116+
10901117
if ( loc != curloc ) continue;
10911118

10921119
if ( mUpdate && mapset != QgsGrass::getDefaultMapset() ) continue;
@@ -1139,8 +1166,9 @@ void QgsGrassModuleInput::updateQgisLayers()
11391166
QString mapset = split.last();
11401167
split.pop_back(); // mapset
11411168

1142-
QDir locDir ( sep + split.join ( QString(sep) ) ) ;
1143-
QString loc = locDir.canonicalPath();
1169+
//QDir locDir ( sep + split.join ( QString(sep) ) ) ;
1170+
//QString loc = locDir.canonicalPath();
1171+
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );
11441172

11451173
QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
11461174
QString curloc = curlocDir.canonicalPath();

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
8787

8888
public slots:
8989
//! Run the module with current options
90+
void on_mRunButton_clicked() { run(); }
9091
void run ();
9192

9293
//! Close the module tab
94+
void on_mCloseButton_clicked() { close(); }
9395
void close ();
9496

9597
//! Running process finished

‎src/plugins/grass/qgsgrassregion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern "C" {
6161

6262
bool QgsGrassRegion::mRunning = false;
6363

64-
QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *interface,
64+
QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
6565
QWidget * parent, const char * name, Qt::WFlags f )
6666
//:QgsGrassRegionBase ( parent, name, f )
6767
//Tim removed params durint qt4 ui port - FIXME
@@ -74,7 +74,7 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
7474
mRunning = true;
7575
mPlugin = plugin;
7676
mQgisApp = qgisApp;
77-
mInterface = interface;
77+
mInterface = iface;
7878
mCanvas = mInterface->getMapCanvas();
7979
restorePosition();
8080
mDraw = false;

‎src/plugins/grass/qgsgrassregion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase
4242

4343
public:
4444
//! Constructor
45-
QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *interface,
45+
QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
4646
QWidget * parent = 0, const char * name = 0,
4747
Qt::WFlags f = 0 );
4848

‎src/plugins/grass/qgsgrassshell.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extern "C" {
3535
#include <stdio.h>
3636
#include <stdlib.h>
3737
#include <unistd.h>
38+
39+
#ifndef WIN32
3840
#ifdef Q_OS_MACX
3941
#include <util.h>
4042
#else
@@ -44,6 +46,7 @@ extern "C" {
4446
#include <sys/stat.h>
4547
#include <sys/ioctl.h>
4648
#include <fcntl.h>
49+
#endif //!WIN32
4750
}
4851

4952
#define QGISDEBUG 1
@@ -56,6 +59,12 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
5659
{
5760
mValid = false;
5861

62+
#ifdef WIN32
63+
QMessageBox::warning( 0, "Warning",
64+
"GRASS Shell is not supported on Windows." );
65+
return;
66+
#else
67+
5968
QGridLayout *layout = new QGridLayout( mTextFrame, 1, 1 );
6069
mText = new QgsGrassShellText( this, mTextFrame);
6170
layout->addWidget ( mText, 0 , 0 );
@@ -227,6 +236,7 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
227236

228237
resizeTerminal();
229238
mValid = true;
239+
#endif // !WIN32
230240
}
231241

232242
QgsGrassShell::~QgsGrassShell()
@@ -838,18 +848,20 @@ void QgsGrassShell::resizeTerminal()
838848
int col = (int) (width / fm.width("x"));
839849
int row = (int) (height / fm.height());
840850

851+
#ifndef WIN32
841852
struct winsize winSize;
842853
memset(&winSize, 0, sizeof(winSize));
843854
winSize.ws_row = row;
844855
winSize.ws_col = col;
845856

846857
ioctl( mFdMaster, TIOCSWINSZ, (char *)&winSize );
858+
#endif
847859
}
848860

849861
void QgsGrassShell::readStderr()
850862
{
851863
}
852-
864+
853865
QgsGrassShellText::QgsGrassShellText ( QgsGrassShell *gs,
854866
QWidget * parent, const char *name )
855867
: Q3TextEdit (parent,name),
@@ -892,4 +904,3 @@ void QgsGrassShellText::resizeEvent(QResizeEvent *e)
892904
mShell->resizeTerminal();
893905
Q3TextEdit::resizeEvent(e);
894906
}
895-

‎src/plugins/grass/qgsgrassshell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <QMouseEvent>
1313
#include <QKeyEvent>
1414
#include <QResizeEvent>
15-
15+
1616
class QgsGrassShellText;
1717

1818
extern "C" {

‎src/plugins/grass/qgsgrasstools.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <QCloseEvent>
5252

5353
#include "qgis.h"
54+
#include "qgsapplication.h"
5455
#include "qgsmapcanvas.h"
5556
#include "qgsmaplayer.h"
5657
#include "qgsvectorlayer.h"
@@ -74,12 +75,14 @@ QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
7475
QWidget * parent, const char * name, Qt::WFlags f )
7576
//:QgsGrassToolsBase ( parent, name, f )
7677
//commented out params during Qt4 Ui port - FIXME
77-
:QgsGrassToolsBase ( )
78+
:QgsGrassToolsBase ( ), Q3MainWindow()
7879
{
7980
#ifdef QGISDEBUG
8081
std::cerr << "QgsGrassTools()" << std::endl;
8182
#endif
8283

84+
setupUi(this);
85+
8386
mQgisApp = qgisApp;
8487
mIface = iface;
8588
mCanvas = mIface->getMapCanvas();
@@ -95,42 +98,61 @@ QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
9598
connect( mModulesListView, SIGNAL(clicked(Q3ListViewItem *)),
9699
this, SLOT(moduleClicked( Q3ListViewItem *)) );
97100

101+
QString title = "GRASS Tools: " + QgsGrass::getDefaultLocation()
102+
+ "/" + QgsGrass::getDefaultMapset();
103+
setCaption(title);
104+
105+
// Warning: QgsApplication initialized in main.cpp
106+
// is not valid here (static libraries / linking)
107+
98108
#if defined(WIN32) || defined(Q_OS_MACX)
99109
mAppDir = qApp->applicationDirPath();
100110
#else
101111
mAppDir = PREFIX;
102112
#endif
103113

104-
QString title = "GRASS Tools: " + QgsGrass::getDefaultLocation()
105-
+ "/" + QgsGrass::getDefaultMapset();
106-
setCaption(title);
107-
114+
//QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
108115
QString conf = mAppDir + "/share/qgis/grass/config/default.qgc";
116+
109117
loadConfig ( conf );
110118
//statusBar()->hide();
111119
restorePosition();
112120
}
113121

114122
void QgsGrassTools::moduleClicked( Q3ListViewItem * item )
115123
{
124+
#ifdef QGISDEBUG
125+
std::cerr << "QgsGrassTools::moduleClicked()" << std::endl;
126+
#endif
116127
if ( !item ) return;
117128

118129
QString name = item->text(1);
119130
//std::cerr << "name = " << name << std::endl;
120131

121132
if ( name.length() == 0 ) return; // Section
122133

134+
//QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
123135
QString path = mAppDir + "/share/qgis/grass/modules/" + name;
136+
#ifdef QGISDEBUG
137+
std::cerr << "path = " << path.ascii() << std::endl;
138+
#endif
124139
QWidget *m;
125140
QgsGrassShell *sh = 0;
126141
if ( name == "shell" )
127142
{
128-
#ifdef HAVE_OPENPTY
143+
#ifdef WIN32
144+
QMessageBox::warning( 0, "Warning",
145+
"GRASS Shell is not supported on Windows." );
146+
#else
147+
148+
#ifdef HAVE_OPENPTY
129149
sh = new QgsGrassShell(this, mTabWidget);
130150
m = dynamic_cast<QWidget *> ( sh );
131-
#else
151+
#else
132152
QMessageBox::warning( 0, "Warning", "GRASS Shell is not compiled." );
133-
#endif
153+
#endif // HAVE_OPENPTY
154+
155+
#endif // ! WIN32
134156
}
135157
else
136158
{
@@ -148,7 +170,9 @@ void QgsGrassTools::moduleClicked( Q3ListViewItem * item )
148170

149171
// We must call resize to reset COLUMNS enviroment variable
150172
// used by bash !!!
173+
#ifndef WIN32
151174
if ( sh ) sh->resizeTerminal();
175+
#endif
152176
}
153177

154178
bool QgsGrassTools::loadConfig(QString filePath)
@@ -233,6 +257,7 @@ void QgsGrassTools::addModules ( Q3ListViewItem *parent, QDomElement &element )
233257
QString name = e.attribute("name");
234258
std::cout << "name = " << name.toLocal8Bit().data() << std::endl;
235259

260+
//QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
236261
QString path = mAppDir + "/share/qgis/grass/modules/" + name;
237262
QString label = QgsGrassModule::label ( path );
238263
QPixmap pixmap = QgsGrassModule::pixmap ( path, 25 );
@@ -270,6 +295,7 @@ QgsGrassTools::~QgsGrassTools()
270295

271296
QString QgsGrassTools::appDir(void)
272297
{
298+
//return QgsApplication::applicationDirPath();
273299
return mAppDir;
274300
}
275301

‎src/plugins/grass/qgsgrasstools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class QgsGrassProvider;
3636
* \brief Interface to GRASS modules.
3737
*
3838
*/
39-
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
39+
//class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
40+
class QgsGrassTools: public Q3MainWindow, private Ui::QgsGrassToolsBase
4041
{
4142
Q_OBJECT;
4243

0 commit comments

Comments
 (0)
Please sign in to comment.