Skip to content

Commit 96d8f87

Browse files
committedMay 17, 2017
Start on options page
1 parent fb6ba51 commit 96d8f87

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed
 

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ SET(QGIS_APP_SRCS
156156
composer/qgsatlascompositionwidget.cpp
157157

158158
locator/qgsinbuiltlocatorfilters.cpp
159+
locator/qgslocatoroptionswidget.cpp
159160

160161
ogr/qgsogrhelperfunctions.cpp
161162
ogr/qgsopenvectorlayerdialog.cpp
@@ -335,6 +336,7 @@ SET (QGIS_APP_MOC_HDRS
335336
composer/qgsatlascompositionwidget.h
336337

337338
locator/qgsinbuiltlocatorfilters.h
339+
locator/qgslocatoroptionswidget.h
338340

339341
ogr/qgsopenvectorlayerdialog.h
340342
ogr/qgsnewogrconnection.h
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/***************************************************************************
2+
qgslocatoroptionswidget.cpp
3+
---------------------------
4+
begin : May 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
19+
#include "qgslocatoroptionswidget.h"
20+
21+
QgsLocatorOptionsWidget::QgsLocatorOptionsWidget( QgsLocator *locator, QWidget *parent )
22+
: QWidget( parent )
23+
, mLocator( locator )
24+
{
25+
setupUi( this );
26+
27+
mModel = new QgsLocatorFiltersModel( mLocator, this );
28+
mFiltersTreeView->setModel( mModel );
29+
}
30+
31+
32+
//
33+
// QgsLocatorFiltersModel
34+
//
35+
36+
QgsLocatorFiltersModel::QgsLocatorFiltersModel( QgsLocator *locator, QObject *parent )
37+
: QAbstractTableModel( parent )
38+
, mLocator( locator )
39+
{
40+
41+
}
42+
43+
int QgsLocatorFiltersModel::rowCount( const QModelIndex & ) const
44+
{
45+
return mLocator->filters().count();
46+
}
47+
48+
int QgsLocatorFiltersModel::columnCount( const QModelIndex & ) const
49+
{
50+
return 4;
51+
}
52+
53+
QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) const
54+
{
55+
if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
56+
index.row() >= rowCount( QModelIndex() ) || index.column() >= columnCount( QModelIndex() ) )
57+
return QVariant();
58+
59+
switch ( role )
60+
{
61+
case Qt::DisplayRole:
62+
case Qt::EditRole:
63+
{
64+
switch ( index.column() )
65+
{
66+
case Name:
67+
return mLocator->filters().at( index.row() )->displayName();
68+
69+
case Prefix:
70+
return mLocator->filters().at( index.row() )->prefix();
71+
72+
case Active:
73+
case Default:
74+
return QVariant();
75+
}
76+
}
77+
78+
case Qt::CheckStateRole:
79+
switch ( index.column() )
80+
{
81+
case Name:
82+
case Prefix:
83+
return QVariant();
84+
85+
case Active:
86+
return Qt::Checked;
87+
88+
case Default:
89+
return mLocator->filters().at( index.row() )->useWithoutPrefix() ? Qt::Checked : Qt::Unchecked;
90+
}
91+
92+
93+
}
94+
95+
return QVariant();
96+
}
97+
98+
Qt::ItemFlags QgsLocatorFiltersModel::flags( const QModelIndex &index ) const
99+
{
100+
if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
101+
index.row() >= rowCount( QModelIndex() ) || index.column() >= columnCount( QModelIndex() ) )
102+
return QAbstractTableModel::flags( index );
103+
104+
Qt::ItemFlags flags = QAbstractTableModel::flags( index );
105+
switch ( index.column() )
106+
{
107+
case Name:
108+
case Prefix:
109+
break;
110+
111+
case Active:
112+
case Default:
113+
flags = flags | Qt::ItemIsUserCheckable;
114+
break;
115+
}
116+
117+
return flags;
118+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/***************************************************************************
2+
qgslocatoroptionswidget.h
3+
--------------------------
4+
begin : May 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSLOCATOROPTIONSWIDGET_H
19+
#define QGSLOCATOROPTIONSWIDGET_H
20+
21+
#include "qgslocatorfilter.h"
22+
#include "qgslocator.h"
23+
#include "ui_qgslocatoroptionswidgetbase.h"
24+
25+
class QgsLocatorFiltersModel;
26+
27+
class QgsLocatorOptionsWidget : public QWidget, private Ui::QgsLocatorOptionsWidgetBase
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
33+
QgsLocatorOptionsWidget( QgsLocator *locator, QWidget *parent = nullptr );
34+
35+
private:
36+
37+
QgsLocator *mLocator = nullptr;
38+
QgsLocatorFiltersModel *mModel = nullptr;
39+
};
40+
41+
42+
/**
43+
* \class QgsLocatorFiltersModel
44+
* \ingroup app
45+
* An list model for displaying available filters and configuring them.
46+
* \since QGIS 3.0
47+
*/
48+
class QgsLocatorFiltersModel : public QAbstractTableModel
49+
{
50+
Q_OBJECT
51+
52+
public:
53+
54+
//! Custom model roles
55+
enum Role
56+
{
57+
ResultDataRole = Qt::UserRole + 1, //!< QgsLocatorResult data
58+
};
59+
60+
enum Columns
61+
{
62+
Name = 0,
63+
Prefix,
64+
Active,
65+
Default
66+
};
67+
68+
/**
69+
* Constructor for QgsLocatorFiltersModel.
70+
*/
71+
QgsLocatorFiltersModel( QgsLocator *locator, QObject *parent = nullptr );
72+
73+
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
74+
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
75+
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
76+
Qt::ItemFlags flags( const QModelIndex &index ) const override;
77+
78+
private:
79+
80+
QgsLocator *mLocator = nullptr;
81+
};
82+
83+
#endif // QGSLOCATOROPTIONSWIDGET_H
84+
85+

‎src/ui/qgslocatoroptionswidgetbase.ui

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsLocatorOptionsWidgetBase</class>
4+
<widget class="QWidget" name="QgsLocatorOptionsWidgetBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>424</width>
10+
<height>334</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Spatial Bookmarks Panel</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
27+
<number>0</number>
28+
</property>
29+
<item>
30+
<widget class="QTreeView" name="mFiltersTreeView">
31+
<property name="rootIsDecorated">
32+
<bool>false</bool>
33+
</property>
34+
</widget>
35+
</item>
36+
</layout>
37+
</widget>
38+
<resources/>
39+
<connections/>
40+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.