Skip to content

Commit 19b0ddd

Browse files
author
timlinux
committed
Added missing files
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10726 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 868f6be commit 19b0ddd

8 files changed

+511
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/***************************************************************************
2+
QgsAttributeTableDelegate.cpp
3+
--------------------------------------
4+
Date : Feb 2009
5+
Copyright : (C) 2009 Vita Cizek
6+
Email : weetya (at) gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <QItemDelegate>
17+
#include <QLineEdit>
18+
#include <QPainter>
19+
20+
#include "qgsattributetableview.h"
21+
#include "qgsattributetablemodel.h"
22+
#include "qgsattributetabledelegate.h"
23+
#include "qgsvectordataprovider.h"
24+
25+
QWidget * QgsAttributeTableDelegate::createEditor(
26+
QWidget *parent,
27+
const QStyleOptionViewItem &option,
28+
const QModelIndex &index ) const
29+
{
30+
QWidget *editor = QItemDelegate::createEditor( parent, option, index );
31+
32+
QLineEdit *le = dynamic_cast<QLineEdit*>( editor );
33+
if ( !le ) return editor;
34+
35+
const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( index.model() );
36+
if ( !m ) return editor;
37+
38+
int col = index.column();
39+
QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
40+
41+
if ( type == QVariant::Int )
42+
{
43+
le->setValidator( new QIntValidator( le ) );
44+
}
45+
else if ( type == QVariant::Double )
46+
{
47+
le->setValidator( new QDoubleValidator( le ) );
48+
}
49+
50+
return editor;
51+
}
52+
53+
54+
void QgsAttributeTableDelegate::paint( QPainter * painter,
55+
const QStyleOptionViewItem & option,
56+
const QModelIndex & index ) const
57+
{
58+
QItemDelegate::paint( painter, option, index );
59+
60+
if ( option.state & QStyle::State_HasFocus )
61+
{
62+
QRect r = option.rect.adjusted( 1, 1, -1, -1 );
63+
QPen p( QBrush( QColor( 0, 255, 127 ) ), 2 );
64+
painter->save();
65+
painter->setPen( p );
66+
painter->drawRect( r );
67+
painter->restore();
68+
}
69+
}
70+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
QgsAttributeTableDelegate.h
3+
--------------------------------------
4+
Date : Feb 2009
5+
Copyright : (C) 2009 Vita Cizek
6+
Email : weetya (at) gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSATTRIBUTETABLEDELEGATE_H
17+
#define QGSATTRIBUTETABLEDELEGATE_H
18+
19+
#include <QItemDelegate>
20+
class QPainter;
21+
/** \ingroup app
22+
* A delegate item class for QgsAttributeTable (see Qt documentation for
23+
* QItemDelegate).
24+
*/
25+
26+
class QgsAttributeTableDelegate : public QItemDelegate
27+
{
28+
Q_OBJECT;
29+
public:
30+
/** Constructor */
31+
QgsAttributeTableDelegate( QObject* parent = NULL ) :
32+
QItemDelegate( parent ) {};
33+
/** Used to create an editor for when the user tries to
34+
* change the contents of a cell */
35+
QWidget * createEditor(
36+
QWidget *parent,
37+
const QStyleOptionViewItem &option,
38+
const QModelIndex &index ) const;
39+
/** Overloads the paint method form the QItemDelegate bas class */
40+
void paint(
41+
QPainter * painter,
42+
const QStyleOptionViewItem & option,
43+
const QModelIndex & index ) const;
44+
};
45+
46+
#endif //QGSATTRIBUTETABLEDELEGATE_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/***************************************************************************
2+
QgsAttributeTableFilterModel.cpp
3+
--------------------------------------
4+
Date : Feb 2009
5+
Copyright : (C) 2009 Vita Cizek
6+
Email : weetya (at) gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsattributetablefiltermodel.h"
17+
#include "qgsattributetablemodel.h"
18+
#include "qgsvectorlayer.h"
19+
20+
//////////////////
21+
// Filter Model //
22+
//////////////////
23+
24+
void QgsAttributeTableFilterModel::sort( int column, Qt::SortOrder order )
25+
{
26+
(( QgsAttributeTableModel * )sourceModel() )->sort( column, order );
27+
}
28+
29+
QgsAttributeTableFilterModel::QgsAttributeTableFilterModel( QgsVectorLayer* theLayer )
30+
{
31+
mLayer = theLayer;
32+
mHideUnselected = false;
33+
setDynamicSortFilter( true );
34+
}
35+
36+
bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
37+
{
38+
if ( mHideUnselected )
39+
// unreadable? yes, i agree :-)
40+
return mLayer->selectedFeaturesIds().contains((( QgsAttributeTableModel * )sourceModel() )->rowToId( sourceRow ) );
41+
42+
return true;
43+
}
44+
45+
/*
46+
QModelIndex QgsAttributeTableFilterModel::mapFromSource ( const QModelIndex& sourceIndex ) const
47+
{
48+
return sourceIndex;
49+
}
50+
51+
QModelIndex QgsAttributeTableFilterModel::mapToSource ( const QModelIndex& filterIndex ) const
52+
{
53+
return filterIndex;
54+
}
55+
*/
56+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
QgsAttributeTableFilterModel.h - Filter Model for attribute table
3+
-------------------
4+
date : Feb 2009
5+
copyright : Vita Cizek
6+
email : weetya (at) gmail.com
7+
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSATTRIBUTETABLEFILTERMODEL_H
18+
#define QGSATTRIBUTETABLEFILTERMODEL_H
19+
20+
#include <QSortFilterProxyModel>
21+
#include <QModelIndex>
22+
23+
//QGIS Includes
24+
#include "qgsvectorlayer.h" //QgsAttributeList
25+
26+
class QgsAttributeTableFilterModel: public QSortFilterProxyModel
27+
{
28+
public:
29+
QgsAttributeTableFilterModel( QgsVectorLayer* theLayer );
30+
//QModelIndex mapToSource ( const QModelIndex & filterIndex ) const;
31+
//QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const;
32+
bool mHideUnselected;
33+
virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
34+
protected:
35+
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
36+
private:
37+
QgsVectorLayer* mLayer;
38+
};
39+
40+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/***************************************************************************
2+
QgsAttributeTableIdColumnPair.cpp
3+
--------------------------------------
4+
Date : Feb 2009
5+
Copyright : (C) 2009 Vita Cizek
6+
Email : weetya (at) gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsattributetableidcolumnpair.h"
17+
#include "qgsfield.h"
18+
19+
#include <QVariant>
20+
21+
//could be faster when type guessed before sorting
22+
bool QgsAttributeTableIdColumnPair::operator<( const QgsAttributeTableIdColumnPair &b ) const
23+
{
24+
//QVariant thinks gid is a string!
25+
QVariant::Type columnType = columnItem.type();
26+
27+
if ( columnType == QVariant::Int || columnType == QVariant::UInt || columnType == QVariant::LongLong || columnType == QVariant::ULongLong )
28+
return columnItem.toLongLong() < b.columnItem.toLongLong();
29+
30+
if ( columnType == QVariant::Double )
31+
return columnItem.toDouble() < b.columnItem.toDouble();
32+
33+
return columnItem.toString() < b.columnItem.toString();
34+
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/***************************************************************************
2+
QgsAttributeTableIdColumnPair.h - Helper class for attribute tables
3+
-------------------
4+
date : Feb 2009
5+
copyright : Vita Cizek
6+
email : weetya (at) gmail.com
7+
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSATTRIBUTETABKEIDCOLUMNPAIR_H
18+
#define QGSATTRIBUTETABKEIDCOLUMNPAIR_H
19+
20+
#include <QVariant>
21+
22+
class QgsAttributeTableIdColumnPair
23+
{
24+
public:
25+
int id;
26+
QVariant columnItem;
27+
28+
bool operator<( const QgsAttributeTableIdColumnPair &b ) const;
29+
};
30+
31+
#endif

0 commit comments

Comments
 (0)