Public Member Functions

DataWidgetMapper Class Reference

Widget mapper used by MappedBaseEditor. More...

#include <baseeditor.h>

Inheritance diagram for DataWidgetMapper:
Inheritance graph
[legend]
Collaboration diagram for DataWidgetMapper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 DataWidgetMapper (QObject *parent=0)
bool isDirty () const

Detailed Description

Widget mapper used by MappedBaseEditor.

Mainly the extension to check whether it is dirty is important.


Constructor & Destructor Documentation

DataWidgetMapper::DataWidgetMapper ( QObject parent = 0  ) 

                                                            : QDataWidgetMapper(parent)
{
}


Member Function Documentation

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;
}


The documentation for this class was generated from the following files: