| Home · All Classes · Main Classes · Deprecated |
00001 /*************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of libmeegotouch. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 00020 #include "mwidgetmodel.h" 00021 #include "mwidgetmodel_p.h" 00022 00023 #include <QMetaProperty> 00024 #include <MDebug> 00025 00027 // PRIVATE CLASS // 00029 MWidgetModelPrivate::MWidgetModelPrivate() : 00030 transactionInProgress(false), 00031 referenceCount(0) 00032 { 00033 } 00034 00035 MWidgetModelPrivate::~MWidgetModelPrivate() 00036 { 00037 } 00038 00040 // PUBLIC CLASS // 00042 00043 void MWidgetModel::memberModified(const char *const member) 00044 { 00045 if (d_ptr->transactionInProgress) { 00046 d_ptr->modifiedMembers.enqueue(member); 00047 } else { 00048 QList<const char *> list; 00049 list.append(member); 00050 emit modified(list); 00051 } 00052 } 00053 00054 void MWidgetModel::beginTransaction() 00055 { 00056 if (d_ptr->transactionInProgress) { 00057 mWarning("MWidgetModel") << "beginTransaction() - transaction already started!"; 00058 return; 00059 } 00060 00061 d_ptr->transactionInProgress = true; 00062 } 00063 00064 void MWidgetModel::commitTransaction() 00065 { 00066 if (d_ptr->transactionInProgress == false) { 00067 mWarning("MWidgetModel") << "commitTransaction() - no transaction ongoing!"; 00068 return; 00069 } 00070 00071 d_ptr->transactionInProgress = false; 00072 emit modified(d_ptr->modifiedMembers); 00073 d_ptr->modifiedMembers.clear(); 00074 } 00075 00076 void MWidgetModel::increaseReferenceCount() 00077 { 00078 ++d_ptr->referenceCount; 00079 } 00080 00081 void MWidgetModel::decreaseReferenceCount() 00082 { 00083 --d_ptr->referenceCount; 00084 if (d_ptr->referenceCount == 0) 00085 delete this; 00086 } 00087 00088 QDataStream &operator<<(QDataStream &stream, const MWidgetModel &model) 00089 { 00090 const QMetaObject *metaObject = model.metaObject(); 00091 QString hashString = metaObject->className(); 00092 00093 int propertyCount = metaObject->propertyCount(); 00094 for (int i = 0; i != propertyCount; ++i) { 00095 hashString += metaObject->property(i).name(); 00096 hashString += metaObject->property(i).typeName(); 00097 } 00098 00099 uint hash = qHash(hashString); 00100 stream << hash; 00101 for (int i = 0; i != propertyCount; ++i) { 00102 stream << metaObject->property(i).read(&model); 00103 } 00104 00105 return stream; 00106 } 00107 00108 QDataStream &operator>>(QDataStream &stream, MWidgetModel &model) 00109 { 00110 const QMetaObject *metaObject = model.metaObject(); 00111 QString hashString = metaObject->className(); 00112 00113 int propertyCount = metaObject->propertyCount(); 00114 for (int i = 0; i != propertyCount; ++i) { 00115 hashString += metaObject->property(i).name(); 00116 hashString += metaObject->property(i).typeName(); 00117 } 00118 00119 uint realHash = qHash(hashString); 00120 uint hash; 00121 stream >> hash; 00122 if (hash != realHash) { 00123 qFatal("Deserializing of %s failed from QDataStream, Q_PROPERTY table doesn't match!", metaObject->className()); 00124 } 00125 00126 for (int i = 0; i != propertyCount; ++i) { 00127 QVariant v; 00128 stream >> v; 00129 metaObject->property(i).write(&model, v); 00130 } 00131 00132 return stream; 00133 } 00134
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:14:22 (PDT) Doxygen 1.7.1 |
MeeGo Touch |