Skip to content

Commit

Permalink
Start on options page
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 17, 2017
1 parent fb6ba51 commit 96d8f87
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -156,6 +156,7 @@ SET(QGIS_APP_SRCS
composer/qgsatlascompositionwidget.cpp

locator/qgsinbuiltlocatorfilters.cpp
locator/qgslocatoroptionswidget.cpp

ogr/qgsogrhelperfunctions.cpp
ogr/qgsopenvectorlayerdialog.cpp
Expand Down Expand Up @@ -335,6 +336,7 @@ SET (QGIS_APP_MOC_HDRS
composer/qgsatlascompositionwidget.h

locator/qgsinbuiltlocatorfilters.h
locator/qgslocatoroptionswidget.h

ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h
Expand Down
118 changes: 118 additions & 0 deletions src/app/locator/qgslocatoroptionswidget.cpp
@@ -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;
}
85 changes: 85 additions & 0 deletions src/app/locator/qgslocatoroptionswidget.h
@@ -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


40 changes: 40 additions & 0 deletions src/ui/qgslocatoroptionswidgetbase.ui
@@ -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>

0 comments on commit 96d8f87

Please sign in to comment.