Skip to content
Permalink
Browse files

merge from trunk r11100:11150

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11882 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Nov 2, 2009
1 parent d5630cc commit 92cf64dccb36f11a94e0e43b591d6b3ed1bb20c1
Showing with 3,029 additions and 421 deletions.
  1. +1 −1 python/core/qgsvectorlayer.sip
  2. +4 −0 src/app/CMakeLists.txt
  3. +281 −10 src/app/attributetable/qgsattributetabledelegate.cpp
  4. +20 −1 src/app/attributetable/qgsattributetabledelegate.h
  5. +83 −1 src/app/attributetable/qgsattributetabledialog.h
  6. +16 −2 src/app/attributetable/qgsattributetablefiltermodel.h
  7. +4 −0 src/app/attributetable/qgsattributetableidcolumnpair.h
  8. +2 −0 src/app/attributetable/qgsattributetablememorymodel.cpp
  9. +52 −3 src/app/attributetable/qgsattributetablememorymodel.h
  10. +17 −11 src/app/attributetable/qgsattributetablemodel.cpp
  11. +116 −2 src/app/attributetable/qgsattributetablemodel.h
  12. +5 −1 src/app/attributetable/qgsattributetableview.cpp
  13. +22 −0 src/app/attributetable/qgsattributetableview.h
  14. +488 −0 src/app/qgsattributetypedialog.cpp
  15. +136 −0 src/app/qgsattributetypedialog.h
  16. +210 −0 src/app/qgsattributetypeloaddialog.cpp
  17. +98 −0 src/app/qgsattributetypeloaddialog.h
  18. +28 −1 src/app/qgsdbsourceselect.cpp
  19. +3 −0 src/app/qgsdbsourceselect.h
  20. +11 −2 src/app/qgsmaptooldeletevertex.cpp
  21. +293 −28 src/app/qgsmaptoolnodetool.cpp
  22. +44 −5 src/app/qgsmaptoolnodetool.h
  23. +5 −1 src/app/qgsmaptoolsimplify.cpp
  24. +3 −1 src/app/qgsoptions.cpp
  25. +1 −9 src/app/qgspgquerybuilder.cpp
  26. +0 −2 src/app/qgspgquerybuilder.h
  27. +194 −97 src/app/qgsvectorlayerproperties.cpp
  28. +10 −1 src/app/qgsvectorlayerproperties.h
  29. +22 −10 src/core/qgsgeometry.cpp
  30. +1 −22 src/core/qgsvectordataprovider.cpp
  31. +13 −0 src/core/qgsvectordataprovider.h
  32. +5 −1 src/core/qgsvectorlayer.cpp
  33. +1 −1 src/core/qgsvectorlayer.h
  34. +0 −2 src/plugins/grass/modules-6.3/default.qgc
  35. +0 −1 src/plugins/grass/modules-6.4/default.qgc
  36. +1 −1 src/plugins/grass/modules-6.4/r.external.all.qgm
  37. +30 −48 src/plugins/grass/qgsgrassshell.cpp
  38. +1 −6 src/plugins/grass/qgsgrassshell.h
  39. +0 −19 src/plugins/grass/qgsgrasstools.cpp
  40. +10 −0 src/plugins/grass/qtermwidget/qtermwidget.cpp
  41. +3 −0 src/plugins/grass/qtermwidget/qtermwidget.h
  42. +2 −1 src/plugins/grass/scripts/CMakeLists.txt
  43. +1 −1 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  44. +5 −0 src/providers/grass/qgsgrass.cpp
  45. +3 −0 src/providers/grass/qgsgrass.h
  46. +1 −1 src/providers/memory/qgsmemoryprovider.cpp
  47. +3 −7 src/providers/ogr/qgsogrprovider.cpp
  48. +5 −3 src/providers/postgres/qgspostgresprovider.cpp
  49. +1 −1 src/providers/spatialite/qgsspatialiteprovider.cpp
  50. +138 −0 src/ui/qgsattributeloadfrommap.ui
  51. +499 −0 src/ui/qgsattributetypeedit.ui
  52. +111 −98 src/ui/qgsdbsourceselectbase.ui
  53. +26 −19 src/ui/qgsoptionsbase.ui
@@ -434,7 +434,7 @@ public:
/** Finish edit command and add it to undo/redo stack */
void endEditCommand();

/** Destroy active command and deletes all changes in it */
/** Destroy active command and reverts all changes in it */
void destroyEditCommand();

/** Execute undo operation. To be called only from QgsVectorLayerUndoCommand. */
@@ -6,6 +6,8 @@ SET(QGIS_APP_SRCS
qgsaddattrdialog.cpp
qgsattributeactiondialog.cpp
qgsattributedialog.cpp
qgsattributetypedialog.cpp
qgsattributetypeloaddialog.cpp
qgsbookmarkitem.cpp
qgsbookmarks.cpp
qgsclipboard.cpp
@@ -108,6 +110,8 @@ SET (QGIS_APP_MOC_HDRS
qgsaddattrdialog.h
qgsattributeactiondialog.h
qgsattributedialog.h
qgsattributetypedialog.h
qgsattributetypeloaddialog.h
qgsbookmarks.h
qgscontinuouscolordialog.h
qgsconfigureshortcutsdialog.h
@@ -15,38 +15,183 @@

#include <QItemDelegate>
#include <QLineEdit>
#include <QComboBox>
#include <QPainter>
#include <QCompleter>
#include <QSpinBox>
#include <QDoubleSpinBox>

#include "qgsattributetableview.h"
#include "qgsattributetablemodel.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsattributetabledelegate.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsuniquevaluerenderer.h"
#include "qgssymbol.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;
QWidget *editor;

const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( index.model() );
if ( !m ) return editor;
const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
if ( !fm )
{
return editor;
}
const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
if ( !m )
{
return editor;
}

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

//need to created correct edit widget according to edit type of value
//and fill with data from correct source
if (editType == QgsVectorLayer::LineEdit ||
editType == QgsVectorLayer::UniqueValuesEditable ||
editType == QgsVectorLayer::FileName ||
editType == QgsVectorLayer::Immutable)
{ //these are all siple edits
editor = new QLineEdit(parent);
QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
le-> setReadOnly ( false );

if ( editType == QgsVectorLayer::UniqueValuesEditable )
{ //just this value has completer
QList<QVariant> values;
m->layer()->dataProvider()->uniqueValues( col, values );

QStringList svalues;
for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ )
svalues << it->toString();

QCompleter *c = new QCompleter( svalues );
c->setCompletionMode( QCompleter::PopupCompletion );
le->setCompleter( c );
}
if (editType == QgsVectorLayer::Immutable)
{
le->setReadOnly(true);
}
//validators if value needs it
if ( type == QVariant::Int )
{
le->setValidator( new QIntValidator( le ) );
}
else if ( type == QVariant::Double )
{
le->setValidator( new QDoubleValidator( le ) );
}
}
else if (editType == QgsVectorLayer::ValueMap)
{ //simple combobox from data from vector layer
editor = new QComboBox(parent);
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
QMap<QString, QVariant> &map = m->layer()->valueMap(col);
QMap<QString, QVariant>::iterator it = map.begin();
for ( ; it != map.end(); it ++)
{
cb->addItem( it.key() ,it.value());
}
}
else if (editType == QgsVectorLayer::SliderRange)
{ //horizontal slider
editor = new QSlider(Qt::Horizontal, parent);
QSlider* s = dynamic_cast<QSlider*>(editor );
QgsVectorLayer::RangeData &range = m->layer()->range(col);
s->setMinimum( range.mMin.toInt() );
s->setMaximum( range.mMax.toInt() );
s->setPageStep( range.mStep.toInt() );
}
else if (editType == QgsVectorLayer::Classification)
{
// should be prepared probably to not change it always
int classificationField = -1;
QMap<QString, QString> classes;
const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( m->layer()->renderer() );
if ( uvr )
{
classificationField = uvr->classificationField();
const QList<QgsSymbol *> symbols = uvr->symbols();

for ( int i = 0; i < symbols.size(); i++ )
{
QString label = symbols[i]->label();
QString name = symbols[i]->lowerValue();
if ( label == "" )
label = name;
classes.insert( name, label );
}
}
editor = new QComboBox(parent);
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ )
{
cb->addItem( it.value(), it.key() );
}
}
else if (editType == QgsVectorLayer::UniqueValues)
{
QList<QVariant> values;
m->layer()->dataProvider()->uniqueValues( col, values );

editor = new QComboBox(parent);
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
cb->setEditable( true );

if ( type == QVariant::Int )
for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ )
cb->addItem( it->toString() );

}
else if (editType == QgsVectorLayer::Enumeration)
{
le->setValidator( new QIntValidator( le ) );
QStringList enumValues;
m->layer()->dataProvider()->enumValues( col, enumValues );

editor = new QComboBox(parent);
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
QStringList::const_iterator s_it = enumValues.constBegin();
for ( ; s_it != enumValues.constEnd(); ++s_it )
{
cb->addItem( *s_it );
}
}
else if ( type == QVariant::Double )
else if (editType == QgsVectorLayer::EditRange)
{
le->setValidator( new QDoubleValidator( le ) );
if ( type == QVariant::Int )
{
int min = m->layer()->range( col ).mMin.toInt();
int max = m->layer()->range( col ).mMax.toInt();
int step = m->layer()->range( col ).mStep.toInt();
editor = new QSpinBox(parent);
QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );

sb->setRange( min, max );
sb->setSingleStep( step );

}
else if ( type == QVariant::Double )
{
double min = m->layer()->range( col ).mMin.toDouble();
double max = m->layer()->range( col ).mMax.toDouble();
double step = m->layer()->range( col ).mStep.toDouble();
editor = new QDoubleSpinBox(parent);
QDoubleSpinBox* dsb = dynamic_cast<QDoubleSpinBox*>( editor );

dsb->setRange( min, max );
dsb->setSingleStep( step );
}
}


return editor;
}

@@ -68,3 +213,129 @@ void QgsAttributeTableDelegate::paint( QPainter * painter,
}
}


void QgsAttributeTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{


const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
if ( !fm )
{
return;
}
const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
if ( !m )
{
return;
}
int col = index.column();
QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
QgsVectorLayer::EditType editType = m->layer()->editType(col);
if (editType == QgsVectorLayer::LineEdit ||
editType == QgsVectorLayer::UniqueValuesEditable ||
editType == QgsVectorLayer::FileName ||
editType == QgsVectorLayer::Immutable)
{
QString qs = index.model()->data(index, Qt::DisplayRole).toString();

QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
le->setText( qs );
}
else if (editType == QgsVectorLayer::ValueMap ||
editType == QgsVectorLayer::Classification ||
editType == QgsVectorLayer::UniqueValues ||
editType == QgsVectorLayer::Enumeration)
{
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
QVariant qs = index.model()->data(index, Qt::EditRole);
int cbIndex = cb->findData(qs);
if (cbIndex > -1)
{
cb->setCurrentIndex(cbIndex);
}
}
else if (editType == QgsVectorLayer::SliderRange)
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QSlider* s = dynamic_cast<QSlider*>( editor );
s->setValue( value );
}
else if (editType == QgsVectorLayer::EditRange)
{
if ( type == QVariant::Int )
{
QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );
int value = index.model()->data(index, Qt::EditRole).toInt();
sb->setValue( value );
}
else if ( type == QVariant::Double )
{
QDoubleSpinBox* sb = dynamic_cast<QDoubleSpinBox*>( editor );
double value = index.model()->data(index, Qt::EditRole).toDouble();
sb->setValue( value );
}
}
}



void QgsAttributeTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
const QgsAttributeTableFilterModel* fm = dynamic_cast<const QgsAttributeTableFilterModel*>( index.model() );
if ( !fm )
{
return;
}
const QgsAttributeTableModel* m = dynamic_cast<const QgsAttributeTableModel*>( fm->sourceModel() );
if ( !m )
{
return;
}

int col = index.column();
QVariant::Type type = m->layer()->dataProvider()->fields()[col].type();
QgsVectorLayer::EditType editType = m->layer()->editType(col);
if (editType == QgsVectorLayer::LineEdit ||
editType == QgsVectorLayer::UniqueValuesEditable ||
editType == QgsVectorLayer::FileName ||
editType == QgsVectorLayer::Immutable)
{
QLineEdit* le = dynamic_cast<QLineEdit*> ( editor );
QString text = le->text();
QVariant value = QVariant (text);
model->setData( index, value );
}
else if (editType == QgsVectorLayer::ValueMap ||
editType == QgsVectorLayer::Classification ||
editType == QgsVectorLayer::UniqueValues ||
editType == QgsVectorLayer::Enumeration)
{
QComboBox* cb = dynamic_cast<QComboBox*>( editor );
model->setData(index, cb->itemData(cb->currentIndex()));
}
else if (editType == QgsVectorLayer::SliderRange)
{
QSlider* s = dynamic_cast<QSlider*>( editor );
model->setData( index, s->value() );
}
else if (editType == QgsVectorLayer::EditRange)
{
if ( type == QVariant::Int )
{
QSpinBox* sb = dynamic_cast<QSpinBox*>( editor );
model->setData( index, sb->value() );
}
else if ( type == QVariant::Double )
{
QDoubleSpinBox* sb = dynamic_cast<QDoubleSpinBox*>( editor );
model->setData( index, sb->value() );
}
}
}







@@ -17,6 +17,7 @@
#define QGSATTRIBUTETABLEDELEGATE_H

#include <QItemDelegate>
#include "qgsvectorlayer.h"
class QPainter;
/** \ingroup app
* A delegate item class for QgsAttributeTable (see Qt documentation for
@@ -27,7 +28,9 @@ class QgsAttributeTableDelegate : public QItemDelegate
{
Q_OBJECT;
public:
/** Constructor */
/** Constructor
* @param parent parent object
*/
QgsAttributeTableDelegate( QObject* parent = NULL ) :
QItemDelegate( parent ) {};
/** Used to create an editor for when the user tries to
@@ -41,6 +44,22 @@ class QgsAttributeTableDelegate : public QItemDelegate
QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const;

/**
* Sets data to editor widget. Overloads default metod
* @param editor editor which was created by create editor function in this class
* @param index index of field which is to be modified
*/
void setEditorData(QWidget *editor, const QModelIndex &index) const;

/**
* Sets data from editor backk to model. Overloads default metod
* @param editor editor which was created by create editor function in this class
* @param model model where data should be updated
* @param index index of field which is to be modified
*/
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

};

#endif //QGSATTRIBUTETABLEDELEGATE_H

0 comments on commit 92cf64d

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