Skip to content
Permalink
Browse files

Added missing files

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10726 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux
timlinux committed May 4, 2009
1 parent 868f6be commit 19b0ddd7626203f78eddaa9636f59c0e41c2b4bc
@@ -0,0 +1,70 @@
/***************************************************************************
QgsAttributeTableDelegate.cpp
--------------------------------------
Date : Feb 2009
Copyright : (C) 2009 Vita Cizek
Email : weetya (at) gmail.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 <QItemDelegate>
#include <QLineEdit>
#include <QPainter>

#include "qgsattributetableview.h"
#include "qgsattributetablemodel.h"
#include "qgsattributetabledelegate.h"
#include "qgsvectordataprovider.h"

QWidget * QgsAttributeTableDelegate::createEditor(
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const
{
QWidget *editor = QItemDelegate::createEditor( parent, option, index );

QLineEdit *le = dynamic_cast<QLineEdit*>( editor );
if ( !le ) return editor;

const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( index.model() );
if ( !m ) return editor;

int col = index.column();
QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();

if ( type == QVariant::Int )
{
le->setValidator( new QIntValidator( le ) );
}
else if ( type == QVariant::Double )
{
le->setValidator( new QDoubleValidator( le ) );
}

return editor;
}


void QgsAttributeTableDelegate::paint( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
QItemDelegate::paint( painter, option, index );

if ( option.state & QStyle::State_HasFocus )
{
QRect r = option.rect.adjusted( 1, 1, -1, -1 );
QPen p( QBrush( QColor( 0, 255, 127 ) ), 2 );
painter->save();
painter->setPen( p );
painter->drawRect( r );
painter->restore();
}
}

@@ -0,0 +1,46 @@
/***************************************************************************
QgsAttributeTableDelegate.h
--------------------------------------
Date : Feb 2009
Copyright : (C) 2009 Vita Cizek
Email : weetya (at) gmail.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 QGSATTRIBUTETABLEDELEGATE_H
#define QGSATTRIBUTETABLEDELEGATE_H

#include <QItemDelegate>
class QPainter;
/** \ingroup app
* A delegate item class for QgsAttributeTable (see Qt documentation for
* QItemDelegate).
*/

class QgsAttributeTableDelegate : public QItemDelegate
{
Q_OBJECT;
public:
/** Constructor */
QgsAttributeTableDelegate( QObject* parent = NULL ) :
QItemDelegate( parent ) {};
/** Used to create an editor for when the user tries to
* change the contents of a cell */
QWidget * createEditor(
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
/** Overloads the paint method form the QItemDelegate bas class */
void paint(
QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const;
};

#endif //QGSATTRIBUTETABLEDELEGATE_H
@@ -0,0 +1,56 @@
/***************************************************************************
QgsAttributeTableFilterModel.cpp
--------------------------------------
Date : Feb 2009
Copyright : (C) 2009 Vita Cizek
Email : weetya (at) gmail.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 "qgsattributetablefiltermodel.h"
#include "qgsattributetablemodel.h"
#include "qgsvectorlayer.h"

//////////////////
// Filter Model //
//////////////////

void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
{
(( QgsAttributeTableModel * )sourceModel() )->sort( column, order );
}

QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsVectorLayer* theLayer )
{
mLayer = theLayer;
mHideUnselected = false;
setDynamicSortFilter( true );
}

bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
{
if ( mHideUnselected )
// unreadable? yes, i agree :-)
return mLayer->selectedFeaturesIds().contains((( QgsAttributeTableModel * )sourceModel() )->rowToId( sourceRow ) );

return true;
}

/*
QModelIndex QgsAttributeTableFilterModel::mapFromSource ( const QModelIndex& sourceIndex ) const
{
return sourceIndex;
}
QModelIndex QgsAttributeTableFilterModel::mapToSource ( const QModelIndex& filterIndex ) const
{
return filterIndex;
}
*/

@@ -0,0 +1,40 @@
/***************************************************************************
QgsAttributeTableFilterModel.h - Filter Model for attribute table
-------------------
date : Feb 2009
copyright : Vita Cizek
email : weetya (at) gmail.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 QGSATTRIBUTETABLEFILTERMODEL_H
#define QGSATTRIBUTETABLEFILTERMODEL_H

#include <QSortFilterProxyModel>
#include <QModelIndex>

//QGIS Includes
#include "qgsvectorlayer.h" //QgsAttributeList

class QgsAttributeTableFilterModel: public QSortFilterProxyModel
{
public:
QgsAttributeTableFilterModel( QgsVectorLayer* theLayer );
//QModelIndex mapToSource ( const QModelIndex & filterIndex ) const;
//QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
bool mHideUnselected;
virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
private:
QgsVectorLayer* mLayer;
};

#endif
@@ -0,0 +1,35 @@
/***************************************************************************
QgsAttributeTableIdColumnPair.cpp
--------------------------------------
Date : Feb 2009
Copyright : (C) 2009 Vita Cizek
Email : weetya (at) gmail.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 "qgsattributetableidcolumnpair.h"
#include "qgsfield.h"

#include <QVariant>

//could be faster when type guessed before sorting
bool QgsAttributeTableIdColumnPair::operator<( const QgsAttributeTableIdColumnPair &b ) const
{
//QVariant thinks gid is a string!
QVariant::Type columnType = columnItem.type();

if ( columnType == QVariant::Int || columnType == QVariant::UInt || columnType == QVariant::LongLong || columnType == QVariant::ULongLong )
return columnItem.toLongLong() < b.columnItem.toLongLong();

if ( columnType == QVariant::Double )
return columnItem.toDouble() < b.columnItem.toDouble();

return columnItem.toString() < b.columnItem.toString();
}

@@ -0,0 +1,31 @@
/***************************************************************************
QgsAttributeTableIdColumnPair.h - Helper class for attribute tables
-------------------
date : Feb 2009
copyright : Vita Cizek
email : weetya (at) gmail.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 QGSATTRIBUTETABKEIDCOLUMNPAIR_H
#define QGSATTRIBUTETABKEIDCOLUMNPAIR_H

#include <QVariant>

class QgsAttributeTableIdColumnPair
{
public:
int id;
QVariant columnItem;

bool operator<( const QgsAttributeTableIdColumnPair &b ) const;
};

#endif

0 comments on commit 19b0ddd

Please sign in to comment.
You can’t perform that action at this time.