Skip to content

Commit

Permalink
Implement grass toolbox as a designer ui and make toolbox subclass it…
Browse files Browse the repository at this point in the history
… - reduces the amount of manually (programmatically) constructed gui code required.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8778 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jul 14, 2008
1 parent f13b48a commit cc3d6aa
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 79 deletions.
1 change: 1 addition & 0 deletions src/plugins/grass/CMakeLists.txt
Expand Up @@ -42,6 +42,7 @@ SET (GRASS_PLUGIN_SRCS
)

SET (GRASS_PLUGIN_UIS
qgsgrasstoolsbase.ui
qgsgrassselectbase.ui
qgsgrasseditbase.ui
qgsgrassmapcalcbase.ui
Expand Down
78 changes: 19 additions & 59 deletions src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -95,27 +95,14 @@ static QString getShortPath(const QString &path)
}
#endif

QgsGrassToolsTabWidget::QgsGrassToolsTabWidget( QWidget * parent ):
QTabWidget(parent)
{
// Default height seems to be too small for our purpose
int height = (int)(1.5 * tabBar()->iconSize().height());
// Max width (see QgsGrassModule::pixmap for hardcoded sizes)
int width = 3*height + 28 + 29;
tabBar()->setIconSize( QSize(width,height) );
}

QSize QgsGrassToolsTabWidget::iconSize()
{
return tabBar()->iconSize();
}

QgsGrassToolsTabWidget::~QgsGrassToolsTabWidget() {}

QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
QWidget * parent, const char * name, Qt::WFlags f )
: QDialog ( parent )
: QDialog(parent, f ), QgsGrassToolsBase ()
{

setupUi(this);
#ifdef QGISDEBUG
std::cerr << "QgsGrassTools()" << std::endl;
#endif
Expand All @@ -129,33 +116,12 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
connect( qApp, SIGNAL(aboutToQuit()),
this, SLOT(closeTools()) );

mTabWidget = new QgsGrassToolsTabWidget (this);
QVBoxLayout *layout1 = new QVBoxLayout(this);
layout1->addWidget(mTabWidget);

//
// Radims original tree view code.
//
// Warning: if the tree is not the first page modules are
// displayed over the other pages on first load

mModulesListView = new QTreeWidget();
mTabWidget->addTab( mModulesListView, tr("Modules Tree") );
mModulesListView->setColumnCount(1);
QStringList headers;
headers << tr("Modules");
mModulesListView->setHeaderLabels(headers);
// Set list view
mModulesListView->clear();
mModulesListView->setSortingEnabled(false);
mModulesListView->setRootIsDecorated(true);
// mModulesListView->setResizeMode(QTreeWidget::AllColumns);
mModulesListView->header()->hide();

connect( mModulesListView, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );


mModulesTree->header()->hide();
connect( mModulesTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );


//
Expand All @@ -165,20 +131,16 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
mModelProxy = new QSortFilterProxyModel(this);
mModelProxy->setSourceModel(mModelTools);
mModelProxy->setFilterRole(Qt::UserRole + 2);
mListView = new QListView();

mListView->setModel(mModelProxy);
mListView->setFocus();
mListView->setItemDelegateForColumn(0,new QgsDetailedItemDelegate());
mListView->setUniformItemSizes(false);

QWidget * mypBase = new QWidget(this);
QVBoxLayout * mypListTabLayout = new QVBoxLayout(mypBase);
mypListTabLayout->addWidget(mListView);
mFilterInput = new QLineEdit(this);
mypListTabLayout->addWidget(mFilterInput);
mTabWidget->addTab( mypBase, tr("Modules List") );
connect( mFilterInput, SIGNAL(textChanged(QString)),
this, SLOT(filterChanged(QString)) );
//mListView2 = new QListView(this);
//mDockWidget = new QDockWidget(tr("Grass Tools"), 0);
//mDockWidget->setWidget(mListView2);
//mDockWidget->setObjectName("GrassTools");
//mDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
//mIface->addDockWidget(Qt::LeftDockWidgetArea, mDockWidget);
connect( mListView, SIGNAL(clicked(const QModelIndex)),
this, SLOT(listItemClicked(const QModelIndex)));
//
Expand All @@ -201,8 +163,7 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
QString title = tr("GRASS Tools: ") + QgsGrass::getDefaultLocation()
+ "/" + QgsGrass::getDefaultMapset();
setCaption(title);
mModulesListView->show();
mListView->show();


// Add map browser
mBrowser = new QgsGrassBrowser ( mIface, this );
Expand Down Expand Up @@ -322,7 +283,6 @@ void QgsGrassTools::runModule(QString name)
is.addPixmap ( pixmap2 );
mTabWidget->addTab ( m, is, "" );

QgsGrassToolsTabWidget tw;

mTabWidget->setCurrentPage ( mTabWidget->count()-1 );

Expand All @@ -338,8 +298,8 @@ bool QgsGrassTools::loadConfig(QString filePath)
#ifdef QGISDEBUG
std::cerr << "QgsGrassTools::loadConfig(): " << filePath.toLocal8Bit().data() << std::endl;
#endif
mModulesListView->clear();
mModulesListView->setIconSize(QSize(80,22));
mModulesTree->clear();
mModulesTree->setIconSize(QSize(80,22));

QFile file ( filePath );

Expand Down Expand Up @@ -407,15 +367,15 @@ void QgsGrassTools::addModules ( QTreeWidgetItem *parent, QDomElement &element
}
else
{
item = new QTreeWidgetItem( mModulesListView, lastItem );
item = new QTreeWidgetItem( mModulesTree, lastItem );
}

if ( e.tagName() == "section" )
{
QString label = e.attribute("label");
QgsDebugMsg( QString("label = %1").arg(label) );
item->setText( 0, label );
item->setExpanded(true); // for debuging to spare one click
item->setExpanded(true);

addModules ( item, e );

Expand Down Expand Up @@ -548,7 +508,7 @@ void QgsGrassTools::closeTools()
// Helper function for Tim's experimental model list
//

void QgsGrassTools::filterChanged(QString theText)
void QgsGrassTools::on_mFilterInput_textChanged(QString theText)
{
QgsDebugMsg("PluginManager filter changed to :" + theText);
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax(QRegExp::RegExp);
Expand Down
28 changes: 8 additions & 20 deletions src/plugins/grass/qgsgrasstools.h
Expand Up @@ -31,8 +31,11 @@ class QgsGrassProvider;
class QgsGrassBrowser;
class QgsMapCanvas;

#include "ui_qgsgrasstoolsbase.h"

#include <QDialog>
#include <QTabWidget>
#include <QDockWidget>

//
// For experimental filterable list model by Tim
Expand All @@ -42,25 +45,13 @@ class QgsMapCanvas;
#include <QStandardItemModel>
#include <QSortFilterProxyModel>

class QgsGrassToolsTabWidget: public QTabWidget
{
Q_OBJECT;

public:
//! Constructor
QgsGrassToolsTabWidget ( QWidget * parent = 0 );

//! Destructor
~QgsGrassToolsTabWidget();

QSize iconSize();
};

/*! \class QgsGrassTools
* \brief Interface to GRASS modules.
*
*/
class QgsGrassTools: public QDialog
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
{
Q_OBJECT;

Expand Down Expand Up @@ -107,8 +98,8 @@ public slots:
//! Close open tabs with tools
void closeTools();

//! Update the regex used to filter the modules list
void filterChanged(QString theText);
//! Update the regex used to filter the modules list (autoconnect to ui)
void on_mFilterInput_textChanged(QString theText);
//! Run a module when its entry is clicked in the list view
void listItemClicked(const QModelIndex &theIndex );
//! Run a module given its module name e.g. r.in.gdal
Expand All @@ -126,17 +117,14 @@ public slots:
//! Browser
QgsGrassBrowser *mBrowser;

QgsGrassToolsTabWidget *mTabWidget;
QTreeWidget *mModulesListView;


//
// For experimental model & filtered model by Tim
//
QListView * mListView;
QStandardItemModel * mModelTools;
QSortFilterProxyModel * mModelProxy;
QLineEdit * mFilterInput;
QListView * mListView2;
QDockWidget * mDockWidget;

};

Expand Down
118 changes: 118 additions & 0 deletions src/plugins/grass/qgsgrasstoolsbase.ui
@@ -0,0 +1,118 @@
<ui version="4.0" >
<class>QgsGrassToolsBase</class>
<widget class="QDialog" name="QgsGrassToolsBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Grass Tools</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QTabWidget" name="mTabWidget" >
<property name="currentIndex" >
<number>0</number>
</property>
<widget class="QWidget" name="modulesTree" >
<attribute name="title" >
<string>Modules Tree</string>
</attribute>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QTreeWidget" name="mModulesTree" >
<property name="indentation" >
<number>8</number>
</property>
<property name="rootIsDecorated" >
<bool>false</bool>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
<property name="headerHidden" stdset="0" >
<bool>true</bool>
</property>
<column>
<property name="text" >
<string>1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="modulesList" >
<attribute name="title" >
<string>Modules List</string>
</attribute>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QListView" name="mListView" >
<property name="alternatingRowColors" >
<bool>true</bool>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLineEdit" name="mFilterInput" />
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsGrassToolsBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>252</x>
<y>295</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsGrassToolsBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>320</x>
<y>295</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit cc3d6aa

Please sign in to comment.