[QGIS Commit] r8356 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Apr 16 22:18:54 EDT 2008
Author: jef
Date: 2008-04-16 22:18:54 -0400 (Wed, 16 Apr 2008)
New Revision: 8356
Modified:
trunk/qgis/src/app/qgsattributedialog.cpp
trunk/qgis/src/app/qgsattributedialog.h
trunk/qgis/src/app/qgsattributetable.cpp
trunk/qgis/src/app/qgsattributetable.h
Log:
use integer and double validators on attribute dialog and table, fixes #933
Modified: trunk/qgis/src/app/qgsattributedialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.cpp 2008-04-17 02:08:49 UTC (rev 8355)
+++ trunk/qgis/src/app/qgsattributedialog.cpp 2008-04-17 02:18:54 UTC (rev 8356)
@@ -21,6 +21,7 @@
#include <QTableWidgetItem>
#include <QSettings>
+#include <QLineEdit>
QgsAttributeDialog::QgsAttributeDialog(const QgsFieldMap& fields, const QgsAttributeMap& attributes)
: QDialog(),
@@ -44,10 +45,24 @@
mTable->setItem(index, 0, myFieldItem);
// set attribute value
-
QTableWidgetItem * myValueItem = new QTableWidgetItem((*it).toString());
mTable->setItem(index, 1, myValueItem);
+ QLineEdit *le = new QLineEdit();
+
+ le->setFrame(false);
+
+ if( fields[it.key()].type()==QVariant::Int )
+ {
+ le->setValidator( new QIntValidator(le) );
+ }
+ else if( fields[it.key()].type()==QVariant::Double )
+ {
+ le->setValidator( new QDoubleValidator(le) );
+ }
+
+ mTable->setCellWidget(index, 1, le);
+
++index;
}
@@ -67,11 +82,7 @@
QString QgsAttributeDialog::value(int row)
{
- QString val = mTable->item(row,1)->text();
- if(val=="NULL")
- return QString::null;
- else
- return mTable->item(row,1)->text();
+ return static_cast<QLineEdit*>(mTable->cellWidget(row,1))->text();
}
bool QgsAttributeDialog::isDirty(int row)
@@ -89,7 +100,22 @@
int i=0;
for (QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it)
{
- f.changeAttribute(it.key(), QVariant(attdialog.value(i++)) );
+ QString value = attdialog.value(i++);
+
+ switch( fields[it.key()].type() )
+ {
+ case QVariant::Int:
+ f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toInt() ) );
+ break;
+
+ case QVariant::Double:
+ f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toDouble() ) );
+ break;
+
+ default:
+ f.changeAttribute(it.key(), value=="NULL" ? QVariant(QString::null) : QVariant(value) );
+ break;
+ }
}
return true;
}
Modified: trunk/qgis/src/app/qgsattributedialog.h
===================================================================
--- trunk/qgis/src/app/qgsattributedialog.h 2008-04-17 02:08:49 UTC (rev 8355)
+++ trunk/qgis/src/app/qgsattributedialog.h 2008-04-17 02:18:54 UTC (rev 8356)
@@ -38,9 +38,6 @@
~QgsAttributeDialog();
- /** Returns the field value of a row */
- QString value(int row);
-
/** Returns if the field value of a row was edited since this dialog opened */
bool isDirty(int row);
@@ -67,6 +64,9 @@
private:
QString _settingsPath;
+ /** Returns the field value of a row */
+ QString value(int row);
+
std::vector<bool> mRowIsDirty;
};
Modified: trunk/qgis/src/app/qgsattributetable.cpp
===================================================================
--- trunk/qgis/src/app/qgsattributetable.cpp 2008-04-17 02:08:49 UTC (rev 8355)
+++ trunk/qgis/src/app/qgsattributetable.cpp 2008-04-17 02:18:54 UTC (rev 8356)
@@ -24,6 +24,8 @@
#include <QClipboard>
#include <QAction>
#include <QMenu>
+#include <QLineEdit>
+#include <QValidator>
#include "qgsattributetable.h"
#include "qgsfeature.h"
@@ -59,6 +61,22 @@
{
}
+QWidget *QgsAttributeTable::createEditor(int row, int col, bool initFromCell ) const
+{
+ QLineEdit *le = static_cast<QLineEdit*>(Q3Table::createEditor(row, col, initFromCell));
+
+ if( mFields[col-1].type()==QVariant::Int )
+ {
+ le->setValidator( new QIntValidator(le) );
+ }
+ else if( mFields[col-1].type()==QVariant::Double )
+ {
+ le->setValidator( new QDoubleValidator(le) );
+ }
+
+ return le;
+}
+
void QgsAttributeTable::columnClicked(int col)
{
QApplication::setOverrideCursor(Qt::waitCursor);
@@ -461,7 +479,10 @@
fieldIndex = provider->indexFromFieldName(record_it.key());
if(fieldIndex != -1)
{
- if( record_it.value()=="NULL" )
+ if( record_it.value()=="NULL" ||
+ ( record_it.value().isEmpty() &&
+ (provider->fields()[fieldIndex].type()==QVariant::Int ||
+ provider->fields()[fieldIndex].type()==QVariant::Double) ) )
newAttMap.insert(fieldIndex, QVariant(QString::null) );
else
newAttMap.insert(fieldIndex, record_it.value());
@@ -573,9 +594,22 @@
QgsAttributeMap::const_iterator it;
int h = 1;
for (it = attr.begin(); it != attr.end(); ++it)
- {
+ {
+ QString value;
+
// get the field values
- setText(row, h++, it->isNull() ? "NULL" : it->toString());
+ if( it->isNull() )
+ {
+ if( mFields[h-1].type()==QVariant::Int || mFields[h-1].type()==QVariant::Double )
+ value="";
+ else
+ value="NULL";
+ } else {
+ value = it->toString();
+ }
+
+ clearCellWidget(row, h);
+ setText(row, h++, value);
}
}
Modified: trunk/qgis/src/app/qgsattributetable.h
===================================================================
--- trunk/qgis/src/app/qgsattributetable.h 2008-04-17 02:08:49 UTC (rev 8355)
+++ trunk/qgis/src/app/qgsattributetable.h 2008-04-17 02:18:54 UTC (rev 8356)
@@ -157,6 +157,8 @@
Also, mLastSelectedRows is updated*/
bool checkSelectionChanges();
+ virtual QWidget *createEditor(int row, int col, bool initFromCell ) const;
+
signals:
/**Is emitted when a row was selected*/
void selected(int, bool);
More information about the QGIS-commit
mailing list