Skip to content

Commit

Permalink
Win port
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4676 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Jan 13, 2006
1 parent 61ba5de commit a2662dc
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/plugins/grass/Makefile.am
Expand Up @@ -14,7 +14,8 @@ SUBDIRS = config modules themes

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

DEFS=-DGRASS_BASE=\"$(GRASS_BASE)\" -DHAVE_OPENPTY=$(HAVE_OPENPTY)
DEFS=-DGRASS_BASE=\"$(GRASS_BASE)\" -DHAVE_OPENPTY=$(HAVE_OPENPTY)

if !HAVE_QTMAC
PREFIX=-DPREFIX=\"$(prefix)\"
endif
Expand Down
21 changes: 21 additions & 0 deletions src/plugins/grass/Makefile.win
@@ -0,0 +1,21 @@
QGTOP=../../../

LDADD = ../../providers/grass/.libs/libqgisgrass.a $(PLUGIN_LIBS) $(GRASS_LIB)

OBJECTS = $(wildcard *.o)

PLUGIN = .libs/grassplugin.dll

all: objects $(PLUGIN)

objects:
$(MAKE) -f Makefile

$(PLUGIN): $(OBJECTS)
$(CXX) -shared -o $@ $(OBJECTS) $(LDADD)
$(STRIP) $@

install: all
$(INSTALL) -m 755 $(PLUGIN) $(prefix)/lib/qgis/grassplugin.dll

include ../../../Makefile.win.rules
44 changes: 36 additions & 8 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -63,6 +63,7 @@
#include <QGridLayout>

#include "qgis.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
Expand Down Expand Up @@ -93,12 +94,15 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
std::cerr << "QgsGrassModule()" << std::endl;
#endif

setupUi(this);

mPath = path;
mTools = tools;
mQgisApp = qgisApp;
mIface = iface;
mCanvas = mIface->getMapCanvas();
mParent = parent;
//mAppDir = QgsApplication::applicationDirPath();
mAppDir = mTools->appDir();

/* Read module description and create options */
Expand Down Expand Up @@ -187,8 +191,8 @@ QgsGrassModuleOptions::QgsGrassModuleOptions (
mQgisApp = qgisApp;
mIface = iface;
mCanvas = mIface->getMapCanvas();
//mAppDir = QgsApplication::applicationDirPath();
mAppDir = mTools->appDir();

}

QgsGrassModuleOptions::~QgsGrassModuleOptions()
Expand All @@ -212,6 +216,7 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions()" << std::endl;
std::cerr << "PATH = " << getenv ("PATH") << std::endl;
#endif

mXName = xname;
Expand All @@ -221,6 +226,11 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
process->addArgument( mXName );
process->addArgument( "--interface-description" );

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

#ifdef QGISDEBUG
std::cerr << "layer->type() = " << layer->type() << std::endl;
#endif
if ( mType == Vector && layer->type() == QgsMapLayer::VECTOR ) {
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
std::cerr << "vector->providerType() = " << vector->providerType().ascii() << std::endl;
if ( vector->providerType() != "grass" ) continue;

//TODO dynamic_cast ?
Expand All @@ -1065,9 +1079,14 @@ void QgsGrassModuleInput::updateQgisLayers()
}

// TODO add map() mapset() location() gisbase() to grass provider
QString source = QDir::cleanDirPath ( provider->getDataSourceUri() );

QChar sep = QDir::separator();
QString source = QDir::cleanPath ( provider->getDataSourceUri() );
#ifdef QGISDEBUG
std::cerr << "source = " << source.ascii() << std::endl;
#endif

// Note: QDir::cleanPath is using '/' also on Windows
//QChar sep = QDir::separator();
QChar sep = '/';

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

QDir locDir ( sep + split.join ( QString(sep) ) ) ;
QString loc = locDir.canonicalPath();
//QDir locDir ( sep + split.join ( QString(sep) ) ) ;
//QString loc = locDir.canonicalPath();
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );

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

#ifdef QGISDEBUG
std::cerr << "loc = " << loc.ascii() << std::endl;
std::cerr << "curloc = " << curloc.ascii() << std::endl;
std::cerr << "mapset = " << mapset.ascii() << std::endl;
std::cerr << "QgsGrass::getDefaultMapset() = " << QgsGrass::getDefaultMapset().ascii() << std::endl;
#endif

if ( loc != curloc ) continue;

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

QDir locDir ( sep + split.join ( QString(sep) ) ) ;
QString loc = locDir.canonicalPath();
//QDir locDir ( sep + split.join ( QString(sep) ) ) ;
//QString loc = locDir.canonicalPath();
QString loc = source.remove ( QRegExp("/[^/]+/[^/]+/[^/]+$") );

QDir curlocDir ( QgsGrass::getDefaultGisdbase() + sep + QgsGrass::getDefaultLocation() );
QString curloc = curlocDir.canonicalPath();
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -87,9 +87,11 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase

public slots:
//! Run the module with current options
void on_mRunButton_clicked() { run(); }
void run ();

//! Close the module tab
void on_mCloseButton_clicked() { close(); }
void close ();

//! Running process finished
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/grass/qgsgrassregion.cpp
Expand Up @@ -61,7 +61,7 @@ extern "C" {

bool QgsGrassRegion::mRunning = false;

QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *interface,
QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
QWidget * parent, const char * name, Qt::WFlags f )
//:QgsGrassRegionBase ( parent, name, f )
//Tim removed params durint qt4 ui port - FIXME
Expand All @@ -74,7 +74,7 @@ QgsGrassRegion::QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, Qgis
mRunning = true;
mPlugin = plugin;
mQgisApp = qgisApp;
mInterface = interface;
mInterface = iface;
mCanvas = mInterface->getMapCanvas();
restorePosition();
mDraw = false;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassregion.h
Expand Up @@ -42,7 +42,7 @@ class QgsGrassRegion: public QDialog, private Ui::QgsGrassRegionBase

public:
//! Constructor
QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *interface,
QgsGrassRegion ( QgsGrassPlugin *plugin, QgisApp *qgisApp, QgisIface *iface,
QWidget * parent = 0, const char * name = 0,
Qt::WFlags f = 0 );

Expand Down
15 changes: 13 additions & 2 deletions src/plugins/grass/qgsgrassshell.cpp
Expand Up @@ -35,6 +35,8 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#ifndef WIN32
#ifdef Q_OS_MACX
#include <util.h>
#else
Expand All @@ -44,6 +46,7 @@ extern "C" {
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#endif //!WIN32
}

#define QGISDEBUG 1
Expand All @@ -56,6 +59,12 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
{
mValid = false;

#ifdef WIN32
QMessageBox::warning( 0, "Warning",
"GRASS Shell is not supported on Windows." );
return;
#else

QGridLayout *layout = new QGridLayout( mTextFrame, 1, 1 );
mText = new QgsGrassShellText( this, mTextFrame);
layout->addWidget ( mText, 0 , 0 );
Expand Down Expand Up @@ -227,6 +236,7 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,

resizeTerminal();
mValid = true;
#endif // !WIN32
}

QgsGrassShell::~QgsGrassShell()
Expand Down Expand Up @@ -838,18 +848,20 @@ void QgsGrassShell::resizeTerminal()
int col = (int) (width / fm.width("x"));
int row = (int) (height / fm.height());

#ifndef WIN32
struct winsize winSize;
memset(&winSize, 0, sizeof(winSize));
winSize.ws_row = row;
winSize.ws_col = col;

ioctl( mFdMaster, TIOCSWINSZ, (char *)&winSize );
#endif
}

void QgsGrassShell::readStderr()
{
}

QgsGrassShellText::QgsGrassShellText ( QgsGrassShell *gs,
QWidget * parent, const char *name )
: Q3TextEdit (parent,name),
Expand Down Expand Up @@ -892,4 +904,3 @@ void QgsGrassShellText::resizeEvent(QResizeEvent *e)
mShell->resizeTerminal();
Q3TextEdit::resizeEvent(e);
}

2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassshell.h
Expand Up @@ -12,7 +12,7 @@
#include <QMouseEvent>
#include <QKeyEvent>
#include <QResizeEvent>

class QgsGrassShellText;

extern "C" {
Expand Down
42 changes: 34 additions & 8 deletions src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -51,6 +51,7 @@
#include <QCloseEvent>

#include "qgis.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
Expand All @@ -74,12 +75,14 @@ QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
QWidget * parent, const char * name, Qt::WFlags f )
//:QgsGrassToolsBase ( parent, name, f )
//commented out params during Qt4 Ui port - FIXME
:QgsGrassToolsBase ( )
:QgsGrassToolsBase ( ), Q3MainWindow()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassTools()" << std::endl;
#endif

setupUi(this);

mQgisApp = qgisApp;
mIface = iface;
mCanvas = mIface->getMapCanvas();
Expand All @@ -95,42 +98,61 @@ QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
connect( mModulesListView, SIGNAL(clicked(Q3ListViewItem *)),
this, SLOT(moduleClicked( Q3ListViewItem *)) );

QString title = "GRASS Tools: " + QgsGrass::getDefaultLocation()
+ "/" + QgsGrass::getDefaultMapset();
setCaption(title);

// Warning: QgsApplication initialized in main.cpp
// is not valid here (static libraries / linking)

#if defined(WIN32) || defined(Q_OS_MACX)
mAppDir = qApp->applicationDirPath();
#else
mAppDir = PREFIX;
#endif

QString title = "GRASS Tools: " + QgsGrass::getDefaultLocation()
+ "/" + QgsGrass::getDefaultMapset();
setCaption(title);

//QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
QString conf = mAppDir + "/share/qgis/grass/config/default.qgc";

loadConfig ( conf );
//statusBar()->hide();
restorePosition();
}

void QgsGrassTools::moduleClicked( Q3ListViewItem * item )
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassTools::moduleClicked()" << std::endl;
#endif
if ( !item ) return;

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

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

//QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name;
QString path = mAppDir + "/share/qgis/grass/modules/" + name;
#ifdef QGISDEBUG
std::cerr << "path = " << path.ascii() << std::endl;
#endif
QWidget *m;
QgsGrassShell *sh = 0;
if ( name == "shell" )
{
#ifdef HAVE_OPENPTY
#ifdef WIN32
QMessageBox::warning( 0, "Warning",
"GRASS Shell is not supported on Windows." );
#else

#ifdef HAVE_OPENPTY
sh = new QgsGrassShell(this, mTabWidget);
m = dynamic_cast<QWidget *> ( sh );
#else
#else
QMessageBox::warning( 0, "Warning", "GRASS Shell is not compiled." );
#endif
#endif // HAVE_OPENPTY

#endif // ! WIN32
}
else
{
Expand All @@ -148,7 +170,9 @@ void QgsGrassTools::moduleClicked( Q3ListViewItem * item )

// We must call resize to reset COLUMNS enviroment variable
// used by bash !!!
#ifndef WIN32
if ( sh ) sh->resizeTerminal();
#endif
}

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

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

QString QgsGrassTools::appDir(void)
{
//return QgsApplication::applicationDirPath();
return mAppDir;
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qgsgrasstools.h
Expand Up @@ -36,7 +36,8 @@ class QgsGrassProvider;
* \brief Interface to GRASS modules.
*
*/
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
//class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
class QgsGrassTools: public Q3MainWindow, private Ui::QgsGrassToolsBase
{
Q_OBJECT;

Expand Down

0 comments on commit a2662dc

Please sign in to comment.