Skip to content

Commit cc3d6aa

Browse files
author
timlinux
committed
Implement grass toolbox as a designer ui and make toolbox subclass it - 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
1 parent f13b48a commit cc3d6aa

File tree

4 files changed

+146
-79
lines changed

4 files changed

+146
-79
lines changed

src/plugins/grass/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SET (GRASS_PLUGIN_SRCS
4242
)
4343

4444
SET (GRASS_PLUGIN_UIS
45+
qgsgrasstoolsbase.ui
4546
qgsgrassselectbase.ui
4647
qgsgrasseditbase.ui
4748
qgsgrassmapcalcbase.ui

src/plugins/grass/qgsgrasstools.cpp

+19-59
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,14 @@ static QString getShortPath(const QString &path)
9595
}
9696
#endif
9797

98-
QgsGrassToolsTabWidget::QgsGrassToolsTabWidget( QWidget * parent ):
99-
QTabWidget(parent)
100-
{
101-
// Default height seems to be too small for our purpose
102-
int height = (int)(1.5 * tabBar()->iconSize().height());
103-
// Max width (see QgsGrassModule::pixmap for hardcoded sizes)
104-
int width = 3*height + 28 + 29;
105-
tabBar()->setIconSize( QSize(width,height) );
106-
}
107-
108-
QSize QgsGrassToolsTabWidget::iconSize()
109-
{
110-
return tabBar()->iconSize();
111-
}
11298

113-
QgsGrassToolsTabWidget::~QgsGrassToolsTabWidget() {}
11499

115100
QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
116101
QWidget * parent, const char * name, Qt::WFlags f )
117-
: QDialog ( parent )
102+
: QDialog(parent, f ), QgsGrassToolsBase ()
118103
{
104+
105+
setupUi(this);
119106
#ifdef QGISDEBUG
120107
std::cerr << "QgsGrassTools()" << std::endl;
121108
#endif
@@ -129,33 +116,12 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
129116
connect( qApp, SIGNAL(aboutToQuit()),
130117
this, SLOT(closeTools()) );
131118

132-
mTabWidget = new QgsGrassToolsTabWidget (this);
133-
QVBoxLayout *layout1 = new QVBoxLayout(this);
134-
layout1->addWidget(mTabWidget);
135-
136119
//
137120
// Radims original tree view code.
138121
//
139-
// Warning: if the tree is not the first page modules are
140-
// displayed over the other pages on first load
141-
142-
mModulesListView = new QTreeWidget();
143-
mTabWidget->addTab( mModulesListView, tr("Modules Tree") );
144-
mModulesListView->setColumnCount(1);
145-
QStringList headers;
146-
headers << tr("Modules");
147-
mModulesListView->setHeaderLabels(headers);
148-
// Set list view
149-
mModulesListView->clear();
150-
mModulesListView->setSortingEnabled(false);
151-
mModulesListView->setRootIsDecorated(true);
152-
// mModulesListView->setResizeMode(QTreeWidget::AllColumns);
153-
mModulesListView->header()->hide();
154-
155-
connect( mModulesListView, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
156-
this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );
157-
158-
122+
mModulesTree->header()->hide();
123+
connect( mModulesTree, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
124+
this, SLOT(moduleClicked( QTreeWidgetItem *, int)) );
159125

160126

161127
//
@@ -165,20 +131,16 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
165131
mModelProxy = new QSortFilterProxyModel(this);
166132
mModelProxy->setSourceModel(mModelTools);
167133
mModelProxy->setFilterRole(Qt::UserRole + 2);
168-
mListView = new QListView();
134+
169135
mListView->setModel(mModelProxy);
170-
mListView->setFocus();
171136
mListView->setItemDelegateForColumn(0,new QgsDetailedItemDelegate());
172137
mListView->setUniformItemSizes(false);
173-
174-
QWidget * mypBase = new QWidget(this);
175-
QVBoxLayout * mypListTabLayout = new QVBoxLayout(mypBase);
176-
mypListTabLayout->addWidget(mListView);
177-
mFilterInput = new QLineEdit(this);
178-
mypListTabLayout->addWidget(mFilterInput);
179-
mTabWidget->addTab( mypBase, tr("Modules List") );
180-
connect( mFilterInput, SIGNAL(textChanged(QString)),
181-
this, SLOT(filterChanged(QString)) );
138+
//mListView2 = new QListView(this);
139+
//mDockWidget = new QDockWidget(tr("Grass Tools"), 0);
140+
//mDockWidget->setWidget(mListView2);
141+
//mDockWidget->setObjectName("GrassTools");
142+
//mDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
143+
//mIface->addDockWidget(Qt::LeftDockWidgetArea, mDockWidget);
182144
connect( mListView, SIGNAL(clicked(const QModelIndex)),
183145
this, SLOT(listItemClicked(const QModelIndex)));
184146
//
@@ -201,8 +163,7 @@ QgsGrassTools::QgsGrassTools ( QgisInterface *iface,
201163
QString title = tr("GRASS Tools: ") + QgsGrass::getDefaultLocation()
202164
+ "/" + QgsGrass::getDefaultMapset();
203165
setCaption(title);
204-
mModulesListView->show();
205-
mListView->show();
166+
206167

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

325-
QgsGrassToolsTabWidget tw;
326286

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

@@ -338,8 +298,8 @@ bool QgsGrassTools::loadConfig(QString filePath)
338298
#ifdef QGISDEBUG
339299
std::cerr << "QgsGrassTools::loadConfig(): " << filePath.toLocal8Bit().data() << std::endl;
340300
#endif
341-
mModulesListView->clear();
342-
mModulesListView->setIconSize(QSize(80,22));
301+
mModulesTree->clear();
302+
mModulesTree->setIconSize(QSize(80,22));
343303

344304
QFile file ( filePath );
345305

@@ -407,15 +367,15 @@ void QgsGrassTools::addModules ( QTreeWidgetItem *parent, QDomElement &element
407367
}
408368
else
409369
{
410-
item = new QTreeWidgetItem( mModulesListView, lastItem );
370+
item = new QTreeWidgetItem( mModulesTree, lastItem );
411371
}
412372

413373
if ( e.tagName() == "section" )
414374
{
415375
QString label = e.attribute("label");
416376
QgsDebugMsg( QString("label = %1").arg(label) );
417377
item->setText( 0, label );
418-
item->setExpanded(true); // for debuging to spare one click
378+
item->setExpanded(true);
419379

420380
addModules ( item, e );
421381

@@ -548,7 +508,7 @@ void QgsGrassTools::closeTools()
548508
// Helper function for Tim's experimental model list
549509
//
550510

551-
void QgsGrassTools::filterChanged(QString theText)
511+
void QgsGrassTools::on_mFilterInput_textChanged(QString theText)
552512
{
553513
QgsDebugMsg("PluginManager filter changed to :" + theText);
554514
QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax(QRegExp::RegExp);

src/plugins/grass/qgsgrasstools.h

+8-20
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ class QgsGrassProvider;
3131
class QgsGrassBrowser;
3232
class QgsMapCanvas;
3333

34+
#include "ui_qgsgrasstoolsbase.h"
35+
3436
#include <QDialog>
3537
#include <QTabWidget>
38+
#include <QDockWidget>
3639

3740
//
3841
// For experimental filterable list model by Tim
@@ -42,25 +45,13 @@ class QgsMapCanvas;
4245
#include <QStandardItemModel>
4346
#include <QSortFilterProxyModel>
4447

45-
class QgsGrassToolsTabWidget: public QTabWidget
46-
{
47-
Q_OBJECT;
48-
49-
public:
50-
//! Constructor
51-
QgsGrassToolsTabWidget ( QWidget * parent = 0 );
52-
53-
//! Destructor
54-
~QgsGrassToolsTabWidget();
5548

56-
QSize iconSize();
57-
};
5849

5950
/*! \class QgsGrassTools
6051
* \brief Interface to GRASS modules.
6152
*
6253
*/
63-
class QgsGrassTools: public QDialog
54+
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
6455
{
6556
Q_OBJECT;
6657

@@ -107,8 +98,8 @@ public slots:
10798
//! Close open tabs with tools
10899
void closeTools();
109100

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

129-
QgsGrassToolsTabWidget *mTabWidget;
130-
QTreeWidget *mModulesListView;
131-
132120

133121
//
134122
// For experimental model & filtered model by Tim
135123
//
136-
QListView * mListView;
137124
QStandardItemModel * mModelTools;
138125
QSortFilterProxyModel * mModelProxy;
139-
QLineEdit * mFilterInput;
126+
QListView * mListView2;
127+
QDockWidget * mDockWidget;
140128

141129
};
142130

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<ui version="4.0" >
2+
<class>QgsGrassToolsBase</class>
3+
<widget class="QDialog" name="QgsGrassToolsBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>400</width>
9+
<height>300</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>Grass Tools</string>
14+
</property>
15+
<layout class="QGridLayout" >
16+
<item row="0" column="0" >
17+
<widget class="QTabWidget" name="mTabWidget" >
18+
<property name="currentIndex" >
19+
<number>0</number>
20+
</property>
21+
<widget class="QWidget" name="modulesTree" >
22+
<attribute name="title" >
23+
<string>Modules Tree</string>
24+
</attribute>
25+
<layout class="QGridLayout" >
26+
<item row="0" column="0" >
27+
<widget class="QTreeWidget" name="mModulesTree" >
28+
<property name="indentation" >
29+
<number>8</number>
30+
</property>
31+
<property name="rootIsDecorated" >
32+
<bool>false</bool>
33+
</property>
34+
<property name="wordWrap" >
35+
<bool>true</bool>
36+
</property>
37+
<property name="headerHidden" stdset="0" >
38+
<bool>true</bool>
39+
</property>
40+
<column>
41+
<property name="text" >
42+
<string>1</string>
43+
</property>
44+
</column>
45+
</widget>
46+
</item>
47+
</layout>
48+
</widget>
49+
<widget class="QWidget" name="modulesList" >
50+
<attribute name="title" >
51+
<string>Modules List</string>
52+
</attribute>
53+
<layout class="QGridLayout" >
54+
<item row="0" column="0" >
55+
<widget class="QListView" name="mListView" >
56+
<property name="alternatingRowColors" >
57+
<bool>true</bool>
58+
</property>
59+
<property name="wordWrap" >
60+
<bool>true</bool>
61+
</property>
62+
</widget>
63+
</item>
64+
<item row="1" column="0" >
65+
<widget class="QLineEdit" name="mFilterInput" />
66+
</item>
67+
</layout>
68+
</widget>
69+
</widget>
70+
</item>
71+
<item row="1" column="0" >
72+
<widget class="QDialogButtonBox" name="buttonBox" >
73+
<property name="orientation" >
74+
<enum>Qt::Horizontal</enum>
75+
</property>
76+
<property name="standardButtons" >
77+
<set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::NoButton</set>
78+
</property>
79+
</widget>
80+
</item>
81+
</layout>
82+
</widget>
83+
<resources/>
84+
<connections>
85+
<connection>
86+
<sender>buttonBox</sender>
87+
<signal>accepted()</signal>
88+
<receiver>QgsGrassToolsBase</receiver>
89+
<slot>accept()</slot>
90+
<hints>
91+
<hint type="sourcelabel" >
92+
<x>252</x>
93+
<y>295</y>
94+
</hint>
95+
<hint type="destinationlabel" >
96+
<x>157</x>
97+
<y>274</y>
98+
</hint>
99+
</hints>
100+
</connection>
101+
<connection>
102+
<sender>buttonBox</sender>
103+
<signal>rejected()</signal>
104+
<receiver>QgsGrassToolsBase</receiver>
105+
<slot>reject()</slot>
106+
<hints>
107+
<hint type="sourcelabel" >
108+
<x>320</x>
109+
<y>295</y>
110+
</hint>
111+
<hint type="destinationlabel" >
112+
<x>286</x>
113+
<y>274</y>
114+
</hint>
115+
</hints>
116+
</connection>
117+
</connections>
118+
</ui>

0 commit comments

Comments
 (0)