Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
data browser
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4915 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Feb 28, 2006
1 parent 620a131 commit 983b593
Show file tree
Hide file tree
Showing 6 changed files with 1,062 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/plugins/grass/Makefile.am
Expand Up @@ -35,8 +35,10 @@ plugin_LTLIBRARIES = grassplugin.la

plugin_MOC = qgsgrassplugin.moc.cpp \
qgsgrassselect.moc.cpp \
qgsgrassbrowser.moc.cpp \
qgsgrassedit.moc.cpp \
qgsgrasstools.moc.cpp \
qgsgrassmodel.moc.cpp \
qgsgrassmapcalc.moc.cpp \
qgsgrassmodule.moc.cpp \
qgsgrassnewmapset.moc.cpp \
Expand Down Expand Up @@ -68,10 +70,14 @@ grassplugin_la_SOURCES = qgsgrassplugin.cpp \
qgsgrassplugin.h \
qgsgrassselect.cpp \
qgsgrassselect.h \
qgsgrassbrowser.cpp \
qgsgrassbrowser.h \
qgsgrassedit.cpp \
qgsgrassedit.h \
qgsgrasstools.cpp \
qgsgrasstools.h \
qgsgrassmodel.cpp \
qgsgrassmodel.h \
qgsgrassmapcalc.cpp \
qgsgrassmapcalc.h \
qgsgrassmodule.cpp \
Expand Down
182 changes: 182 additions & 0 deletions src/plugins/grass/qgsgrassbrowser.cpp
@@ -0,0 +1,182 @@
/*******************************************************************
qgsgrassbrowser.cpp
-------------------
begin : February, 2006
copyright : (C) 2006 by Radim Blazek
email : radim.blazek@gmail.com
********************************************************************/
/********************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*******************************************************************/
#include <iostream>
#include <vector>

#include <QApplication>
#include <QStyle>
#include <qdir.h>
#include <qfile.h>
#include <qsettings.h>
#include <qstringlist.h>
#include <qmessagebox.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qnamespace.h>
#include <qevent.h>
#include <qsize.h>
#include <qicon.h>
#include <QTreeView>
#include <QHeaderView>
#include <QMainWindow>
#include <QActionGroup>
#include <QToolBar>
#include <QAction>
#include <QTextBrowser>
#include <QSplitter>

#include "qgis.h"
#include "qgsapplication.h"

extern "C" {
#include <grass/gis.h>
#include <grass/Vect.h>
}

#include "../../src/providers/grass/qgsgrass.h"
#include "qgsgrassmodel.h"
#include "qgsgrassbrowser.h"

QgsGrassBrowser::QgsGrassBrowser ( QgisIface *iface,
QWidget * parent, Qt::WFlags f )
:mIface(iface), QMainWindow(parent, Qt::WType_Dialog)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser()" << std::endl;
#endif

QActionGroup *ag = new QActionGroup ( this );
QToolBar *tb = addToolBar(tr("Tools"));

QString myIconPath = QgsApplication::themePath() + "/grass/";
mActionAddMap = new QAction(
QIcon(myIconPath+"grass_add_map.png"),
tr("Add selected map to canvas"), this);
mActionAddMap->setEnabled(false);
ag->addAction ( mActionAddMap );
tb->addAction ( mActionAddMap );
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );

mActionRefresh = new QAction(
QIcon(myIconPath+"grass_refresh.png"),
tr("Refresh"), this);
ag->addAction ( mActionRefresh );
tb->addAction ( mActionRefresh );
connect ( mActionRefresh, SIGNAL(triggered()), this, SLOT(refresh()) );

// Add model
mModel = new QgsGrassModel ( this );

mTree = new QTreeView(0);
mTree->header()->hide();
mTree->setModel(mModel);

mTextBrowser = new QTextBrowser(0);
mTextBrowser->setTextFormat(Qt::RichText);
mTextBrowser->setReadOnly(TRUE);

mSplitter = new QSplitter(0);
mSplitter->addWidget(mTree);
mSplitter->addWidget(mTextBrowser);

this->setCentralWidget(mSplitter);

connect ( mTree->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(selectionChanged(QItemSelection,QItemSelection)) );

connect ( mTree->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
this, SLOT(currentChanged(QModelIndex,QModelIndex)) );
}

QgsGrassBrowser::~QgsGrassBrowser() { }

void QgsGrassBrowser::refresh()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::refresh()" << std::endl;
#endif

mModel->refresh();
mTree->update();
}

void QgsGrassBrowser::addMap()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::addMap()" << std::endl;
#endif

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
bool mapSelected = false;

QList<QModelIndex>::const_iterator it = indexes.begin();
for (; it != indexes.end(); ++it)
{
int type = mModel->itemType(*it);
QString uri = mModel->uri(*it);
if ( type == QgsGrassModel::Raster )
{
std::cerr << "add raster: " << uri.ascii() << std::endl;
mIface->addRasterLayer( uri );
mapSelected = true;
}
else if ( type == QgsGrassModel::VectorLayer )
{
// TODO: common method for vector names
QStringList split = QStringList::split ( '/', uri );
QString layer = split.last();
split.pop_back(); // map
QString vector = split.last();
mIface->addVectorLayer( uri, layer, "grass");
std::cerr << "add vector: " << uri.ascii() << std::endl;
mapSelected = true;
}
}
}

void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::selectionChanged()" << std::endl;
#endif

mActionAddMap->setEnabled(false);

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();

mTextBrowser->clear();

QList<QModelIndex>::const_iterator it = indexes.begin();
for (; it != indexes.end(); ++it)
{
mTextBrowser->append ( mModel->itemInfo(*it) );

int type = mModel->itemType(*it);
if ( type == QgsGrassModel::Raster || type == QgsGrassModel::VectorLayer )
{
mActionAddMap->setEnabled(true);
}
}

}

void QgsGrassBrowser::currentChanged(const QModelIndex & current, const QModelIndex & previous)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::currentChanged()" << std::endl;
#endif
}

77 changes: 77 additions & 0 deletions src/plugins/grass/qgsgrassbrowser.h
@@ -0,0 +1,77 @@
/***************************************************************************
qgsgrasstree.h
-------------------
begin : February, 2006
copyright : (C) 2006 by Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSBROWSER_H
#define QGSGRASSBROWSER_H

#include <QMainWindow>
class QSplitter;
class QAction;
class QTreeView;
class QTextBrowser;
class QDirModel;

#include "qgisiface.h"
#include "qgsgrassmodel.h"

/*! \class QgsGrassBrowser
* \brief Model representing GRASS location structure.
*/
class QgsGrassBrowser: public QMainWindow
{
Q_OBJECT;

public:
//! Constructor
QgsGrassBrowser ( QgisIface *iface, QWidget * parent = 0, Qt::WFlags f = 0 );

//! Destructor
~QgsGrassBrowser();

public slots:
// Add selected map to canvas
void addMap();

// Refresh model
void refresh();

// Called when tree selection changes
void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
void currentChanged(const QModelIndex & current, const QModelIndex & previous);

private:
QgisIface *mIface;

//! Current GISBASE
QString mGisbase;

//! Current LOCATION_NAME
QString mLocation;

// ! Data model
QgsGrassModel *mModel;

QSplitter *mSplitter;

QTreeView *mTree;

QTextBrowser *mTextBrowser;

//! Actions
QAction *mActionAddMap;
QAction *mActionRefresh;
};

#endif // QGSGRASSBROWSER_H

0 comments on commit 983b593

Please sign in to comment.