Widget mapper used by MappedBaseEditor. More...
#include <baseeditor.h>


Public Member Functions | |
| DataWidgetMapper (QObject *parent=0) | |
| bool | isDirty () const |
Widget mapper used by MappedBaseEditor.
Mainly the extension to check whether it is dirty is important.
| DataWidgetMapper::DataWidgetMapper | ( | QObject * | parent = 0 |
) |
: QDataWidgetMapper(parent) { }
| bool DataWidgetMapper::isDirty | ( | ) | const |
Referenced by MappedBaseEditor::isDirty().
{
Q_ASSERT(orientation() == Qt::Horizontal);
Q_ASSERT(rootIndex() == QModelIndex());
if (model()->rowCount() == 0) return false;
// compare current record and widget data
for(int i = 0; i < model()->columnCount(); i++) {
QWidget *mapWidget = mappedWidgetAt(i);
// widget sanity check
if (mapWidget){
// index sanity check
QModelIndex index = model()->index(currentIndex(), i);
Q_ASSERT(index.isValid());
QByteArray p = mappedPropertyName(mapWidget);
QVariant modelData = index.data(Qt::EditRole);
// This is a little hack becase QComboBox has no userProperty
// so p and modeldata are adjusted so they can be compared.
if (p.isEmpty() && mapWidget->inherits("QComboBox")){
//if (!modelData.isValid()) modelData.setValue(QString()); //With OnManualSubmit, the QVariants of the new record aren't initialized with the table's types, as is the case with OnRowChange
Q_ASSERT(modelData.canConvert(QVariant::String));
modelData.convert(QVariant::String);
p = "currentText";
}
// qDebug() << "-------------------------------\n"
// << modelData << "\n"
// << mapWidget->property(p)
// << "\n-------------------------------";
if (modelData != mapWidget->property(p))
return true;
}
}
return false;
}
1.7.1