Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
245 additions
and 0 deletions.
@@ -0,0 +1,118 @@ | ||
/*************************************************************************** | ||
qgslocatoroptionswidget.cpp | ||
--------------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot 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 "qgslocatoroptionswidget.h" | ||
|
||
QgsLocatorOptionsWidget::QgsLocatorOptionsWidget( QgsLocator *locator, QWidget *parent ) | ||
: QWidget( parent ) | ||
, mLocator( locator ) | ||
{ | ||
setupUi( this ); | ||
|
||
mModel = new QgsLocatorFiltersModel( mLocator, this ); | ||
mFiltersTreeView->setModel( mModel ); | ||
} | ||
|
||
|
||
// | ||
// QgsLocatorFiltersModel | ||
// | ||
|
||
QgsLocatorFiltersModel::QgsLocatorFiltersModel( QgsLocator *locator, QObject *parent ) | ||
: QAbstractTableModel( parent ) | ||
, mLocator( locator ) | ||
{ | ||
|
||
} | ||
|
||
int QgsLocatorFiltersModel::rowCount( const QModelIndex & ) const | ||
{ | ||
return mLocator->filters().count(); | ||
} | ||
|
||
int QgsLocatorFiltersModel::columnCount( const QModelIndex & ) const | ||
{ | ||
return 4; | ||
} | ||
|
||
QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) const | ||
{ | ||
if ( !index.isValid() || index.row() < 0 || index.column() < 0 || | ||
index.row() >= rowCount( QModelIndex() ) || index.column() >= columnCount( QModelIndex() ) ) | ||
return QVariant(); | ||
|
||
switch ( role ) | ||
{ | ||
case Qt::DisplayRole: | ||
case Qt::EditRole: | ||
{ | ||
switch ( index.column() ) | ||
{ | ||
case Name: | ||
return mLocator->filters().at( index.row() )->displayName(); | ||
|
||
case Prefix: | ||
return mLocator->filters().at( index.row() )->prefix(); | ||
|
||
case Active: | ||
case Default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
case Qt::CheckStateRole: | ||
switch ( index.column() ) | ||
{ | ||
case Name: | ||
case Prefix: | ||
return QVariant(); | ||
|
||
case Active: | ||
return Qt::Checked; | ||
|
||
case Default: | ||
return mLocator->filters().at( index.row() )->useWithoutPrefix() ? Qt::Checked : Qt::Unchecked; | ||
} | ||
|
||
|
||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
Qt::ItemFlags QgsLocatorFiltersModel::flags( const QModelIndex &index ) const | ||
{ | ||
if ( !index.isValid() || index.row() < 0 || index.column() < 0 || | ||
index.row() >= rowCount( QModelIndex() ) || index.column() >= columnCount( QModelIndex() ) ) | ||
return QAbstractTableModel::flags( index ); | ||
|
||
Qt::ItemFlags flags = QAbstractTableModel::flags( index ); | ||
switch ( index.column() ) | ||
{ | ||
case Name: | ||
case Prefix: | ||
break; | ||
|
||
case Active: | ||
case Default: | ||
flags = flags | Qt::ItemIsUserCheckable; | ||
break; | ||
} | ||
|
||
return flags; | ||
} |
@@ -0,0 +1,85 @@ | ||
/*************************************************************************** | ||
qgslocatoroptionswidget.h | ||
-------------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot 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 QGSLOCATOROPTIONSWIDGET_H | ||
#define QGSLOCATOROPTIONSWIDGET_H | ||
|
||
#include "qgslocatorfilter.h" | ||
#include "qgslocator.h" | ||
#include "ui_qgslocatoroptionswidgetbase.h" | ||
|
||
class QgsLocatorFiltersModel; | ||
|
||
class QgsLocatorOptionsWidget : public QWidget, private Ui::QgsLocatorOptionsWidgetBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsLocatorOptionsWidget( QgsLocator *locator, QWidget *parent = nullptr ); | ||
|
||
private: | ||
|
||
QgsLocator *mLocator = nullptr; | ||
QgsLocatorFiltersModel *mModel = nullptr; | ||
}; | ||
|
||
|
||
/** | ||
* \class QgsLocatorFiltersModel | ||
* \ingroup app | ||
* An list model for displaying available filters and configuring them. | ||
* \since QGIS 3.0 | ||
*/ | ||
class QgsLocatorFiltersModel : public QAbstractTableModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
//! Custom model roles | ||
enum Role | ||
{ | ||
ResultDataRole = Qt::UserRole + 1, //!< QgsLocatorResult data | ||
}; | ||
|
||
enum Columns | ||
{ | ||
Name = 0, | ||
Prefix, | ||
Active, | ||
Default | ||
}; | ||
|
||
/** | ||
* Constructor for QgsLocatorFiltersModel. | ||
*/ | ||
QgsLocatorFiltersModel( QgsLocator *locator, QObject *parent = nullptr ); | ||
|
||
int rowCount( const QModelIndex &parent = QModelIndex() ) const override; | ||
int columnCount( const QModelIndex &parent = QModelIndex() ) const override; | ||
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override; | ||
Qt::ItemFlags flags( const QModelIndex &index ) const override; | ||
|
||
private: | ||
|
||
QgsLocator *mLocator = nullptr; | ||
}; | ||
|
||
#endif // QGSLOCATOROPTIONSWIDGET_H | ||
|
||
|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>QgsLocatorOptionsWidgetBase</class> | ||
<widget class="QWidget" name="QgsLocatorOptionsWidgetBase"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>424</width> | ||
<height>334</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Spatial Bookmarks Panel</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
<item> | ||
<widget class="QTreeView" name="mFiltersTreeView"> | ||
<property name="rootIsDecorated"> | ||
<bool>false</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |