1 //****************************************************************************** 2 // Copyright (c) 2005-2013 by Jan Van hijfte 3 // 4 // See the included file COPYING.TXT for details about the copyright. 5 // 6 // This program is distributed in the hope that it will be useful, 7 // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 //****************************************************************************** 10 11 12 #ifndef QABSTRACTITEMMODEL_HOOK_H 13 #define QABSTRACTITEMMODEL_HOOK_H 14 15 #include <qabstractitemmodel.h> 16 17 #include "qobject_hook.h" 18 19 class QModelIndex_hook : public QObject_hook { 20 Q_OBJECT 21 public: QModelIndex_hook(QObject * handle)22 QModelIndex_hook(QObject *handle) : QObject_hook(handle) { 23 } 24 }; 25 26 27 #include "qobject_hook.h" 28 29 class QPersistentModelIndex_hook : public QObject_hook { 30 Q_OBJECT 31 public: QPersistentModelIndex_hook(QObject * handle)32 QPersistentModelIndex_hook(QObject *handle) : QObject_hook(handle) { 33 } 34 }; 35 36 37 #include "qobject_hook.h" 38 39 class QAbstractItemModel_hook : public QObject_hook { 40 Q_OBJECT 41 public: QAbstractItemModel_hook(QObject * handle)42 QAbstractItemModel_hook(QObject *handle) : QObject_hook(handle) { 43 dataChanged_event.func = NULL; 44 headerDataChanged_event.func = NULL; 45 layoutChanged_event.func = NULL; 46 layoutAboutToBeChanged_event.func = NULL; 47 rowsAboutToBeInserted_event.func = NULL; 48 rowsInserted_event.func = NULL; 49 rowsAboutToBeRemoved_event.func = NULL; 50 rowsRemoved_event.func = NULL; 51 columnsAboutToBeInserted_event.func = NULL; 52 columnsInserted_event.func = NULL; 53 columnsAboutToBeRemoved_event.func = NULL; 54 columnsRemoved_event.func = NULL; 55 modelAboutToBeReset_event.func = NULL; 56 modelReset_event.func = NULL; 57 rowsAboutToBeMoved_event.func = NULL; 58 rowsMoved_event.func = NULL; 59 columnsAboutToBeMoved_event.func = NULL; 60 columnsMoved_event.func = NULL; 61 } hook_dataChanged(QHook & hook)62 void hook_dataChanged(QHook &hook) { 63 if ( !dataChanged_event.func ) 64 connect(handle, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged_hook(const QModelIndex&, const QModelIndex&))); 65 dataChanged_event = hook; 66 if ( !hook.func ) 67 disconnect(handle, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged_hook(const QModelIndex&, const QModelIndex&))); 68 } hook_headerDataChanged(QHook & hook)69 void hook_headerDataChanged(QHook &hook) { 70 if ( !headerDataChanged_event.func ) 71 connect(handle, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), this, SLOT(headerDataChanged_hook(Qt::Orientation, int, int))); 72 headerDataChanged_event = hook; 73 if ( !hook.func ) 74 disconnect(handle, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), this, SLOT(headerDataChanged_hook(Qt::Orientation, int, int))); 75 } hook_layoutChanged(QHook & hook)76 void hook_layoutChanged(QHook &hook) { 77 if ( !layoutChanged_event.func ) 78 connect(handle, SIGNAL(layoutChanged()), this, SLOT(layoutChanged_hook())); 79 layoutChanged_event = hook; 80 if ( !hook.func ) 81 disconnect(handle, SIGNAL(layoutChanged()), this, SLOT(layoutChanged_hook())); 82 } hook_layoutAboutToBeChanged(QHook & hook)83 void hook_layoutAboutToBeChanged(QHook &hook) { 84 if ( !layoutAboutToBeChanged_event.func ) 85 connect(handle, SIGNAL(layoutAboutToBeChanged()), this, SLOT(layoutAboutToBeChanged_hook())); 86 layoutAboutToBeChanged_event = hook; 87 if ( !hook.func ) 88 disconnect(handle, SIGNAL(layoutAboutToBeChanged()), this, SLOT(layoutAboutToBeChanged_hook())); 89 } hook_rowsAboutToBeInserted(QHook & hook)90 void hook_rowsAboutToBeInserted(QHook &hook) { 91 if ( !rowsAboutToBeInserted_event.func ) 92 connect(handle, SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int, int)), this, SLOT(rowsAboutToBeInserted_hook(const QModelIndex&, int, int))); 93 rowsAboutToBeInserted_event = hook; 94 if ( !hook.func ) 95 disconnect(handle, SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int, int)), this, SLOT(rowsAboutToBeInserted_hook(const QModelIndex&, int, int))); 96 } hook_rowsInserted(QHook & hook)97 void hook_rowsInserted(QHook &hook) { 98 if ( !rowsInserted_event.func ) 99 connect(handle, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(rowsInserted_hook(const QModelIndex&, int, int))); 100 rowsInserted_event = hook; 101 if ( !hook.func ) 102 disconnect(handle, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(rowsInserted_hook(const QModelIndex&, int, int))); 103 } hook_rowsAboutToBeRemoved(QHook & hook)104 void hook_rowsAboutToBeRemoved(QHook &hook) { 105 if ( !rowsAboutToBeRemoved_event.func ) 106 connect(handle, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)), this, SLOT(rowsAboutToBeRemoved_hook(const QModelIndex&, int, int))); 107 rowsAboutToBeRemoved_event = hook; 108 if ( !hook.func ) 109 disconnect(handle, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)), this, SLOT(rowsAboutToBeRemoved_hook(const QModelIndex&, int, int))); 110 } hook_rowsRemoved(QHook & hook)111 void hook_rowsRemoved(QHook &hook) { 112 if ( !rowsRemoved_event.func ) 113 connect(handle, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(rowsRemoved_hook(const QModelIndex&, int, int))); 114 rowsRemoved_event = hook; 115 if ( !hook.func ) 116 disconnect(handle, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(rowsRemoved_hook(const QModelIndex&, int, int))); 117 } hook_columnsAboutToBeInserted(QHook & hook)118 void hook_columnsAboutToBeInserted(QHook &hook) { 119 if ( !columnsAboutToBeInserted_event.func ) 120 connect(handle, SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int, int)), this, SLOT(columnsAboutToBeInserted_hook(const QModelIndex&, int, int))); 121 columnsAboutToBeInserted_event = hook; 122 if ( !hook.func ) 123 disconnect(handle, SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int, int)), this, SLOT(columnsAboutToBeInserted_hook(const QModelIndex&, int, int))); 124 } hook_columnsInserted(QHook & hook)125 void hook_columnsInserted(QHook &hook) { 126 if ( !columnsInserted_event.func ) 127 connect(handle, SIGNAL(columnsInserted(const QModelIndex&, int, int)), this, SLOT(columnsInserted_hook(const QModelIndex&, int, int))); 128 columnsInserted_event = hook; 129 if ( !hook.func ) 130 disconnect(handle, SIGNAL(columnsInserted(const QModelIndex&, int, int)), this, SLOT(columnsInserted_hook(const QModelIndex&, int, int))); 131 } hook_columnsAboutToBeRemoved(QHook & hook)132 void hook_columnsAboutToBeRemoved(QHook &hook) { 133 if ( !columnsAboutToBeRemoved_event.func ) 134 connect(handle, SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int, int)), this, SLOT(columnsAboutToBeRemoved_hook(const QModelIndex&, int, int))); 135 columnsAboutToBeRemoved_event = hook; 136 if ( !hook.func ) 137 disconnect(handle, SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int, int)), this, SLOT(columnsAboutToBeRemoved_hook(const QModelIndex&, int, int))); 138 } hook_columnsRemoved(QHook & hook)139 void hook_columnsRemoved(QHook &hook) { 140 if ( !columnsRemoved_event.func ) 141 connect(handle, SIGNAL(columnsRemoved(const QModelIndex&, int, int)), this, SLOT(columnsRemoved_hook(const QModelIndex&, int, int))); 142 columnsRemoved_event = hook; 143 if ( !hook.func ) 144 disconnect(handle, SIGNAL(columnsRemoved(const QModelIndex&, int, int)), this, SLOT(columnsRemoved_hook(const QModelIndex&, int, int))); 145 } hook_modelAboutToBeReset(QHook & hook)146 void hook_modelAboutToBeReset(QHook &hook) { 147 if ( !modelAboutToBeReset_event.func ) 148 connect(handle, SIGNAL(modelAboutToBeReset()), this, SLOT(modelAboutToBeReset_hook())); 149 modelAboutToBeReset_event = hook; 150 if ( !hook.func ) 151 disconnect(handle, SIGNAL(modelAboutToBeReset()), this, SLOT(modelAboutToBeReset_hook())); 152 } hook_modelReset(QHook & hook)153 void hook_modelReset(QHook &hook) { 154 if ( !modelReset_event.func ) 155 connect(handle, SIGNAL(modelReset()), this, SLOT(modelReset_hook())); 156 modelReset_event = hook; 157 if ( !hook.func ) 158 disconnect(handle, SIGNAL(modelReset()), this, SLOT(modelReset_hook())); 159 } hook_rowsAboutToBeMoved(QHook & hook)160 void hook_rowsAboutToBeMoved(QHook &hook) { 161 if ( !rowsAboutToBeMoved_event.func ) 162 connect(handle, SIGNAL(rowsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(rowsAboutToBeMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 163 rowsAboutToBeMoved_event = hook; 164 if ( !hook.func ) 165 disconnect(handle, SIGNAL(rowsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(rowsAboutToBeMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 166 } hook_rowsMoved(QHook & hook)167 void hook_rowsMoved(QHook &hook) { 168 if ( !rowsMoved_event.func ) 169 connect(handle, SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(rowsMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 170 rowsMoved_event = hook; 171 if ( !hook.func ) 172 disconnect(handle, SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(rowsMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 173 } hook_columnsAboutToBeMoved(QHook & hook)174 void hook_columnsAboutToBeMoved(QHook &hook) { 175 if ( !columnsAboutToBeMoved_event.func ) 176 connect(handle, SIGNAL(columnsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(columnsAboutToBeMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 177 columnsAboutToBeMoved_event = hook; 178 if ( !hook.func ) 179 disconnect(handle, SIGNAL(columnsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(columnsAboutToBeMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 180 } hook_columnsMoved(QHook & hook)181 void hook_columnsMoved(QHook &hook) { 182 if ( !columnsMoved_event.func ) 183 connect(handle, SIGNAL(columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(columnsMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 184 columnsMoved_event = hook; 185 if ( !hook.func ) 186 disconnect(handle, SIGNAL(columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(columnsMoved_hook(const QModelIndex&, int, int, const QModelIndex&, int))); 187 } 188 189 private slots: dataChanged_hook(const QModelIndex & topLeft,const QModelIndex & bottomRight)190 void dataChanged_hook(const QModelIndex& topLeft, const QModelIndex& bottomRight) { 191 if ( dataChanged_event.func ) { 192 typedef void (*func_type)(void *data, const QModelIndexH topLeft, const QModelIndexH bottomRight); 193 (*(func_type)dataChanged_event.func)(dataChanged_event.data, (const QModelIndexH)&topLeft, (const QModelIndexH)&bottomRight); 194 } 195 } headerDataChanged_hook(Qt::Orientation orientation,int first,int last)196 void headerDataChanged_hook(Qt::Orientation orientation, int first, int last) { 197 if ( headerDataChanged_event.func ) { 198 typedef void (*func_type)(void *data, Qt::Orientation orientation, int first, int last); 199 (*(func_type)headerDataChanged_event.func)(headerDataChanged_event.data, orientation, first, last); 200 } 201 } layoutChanged_hook()202 void layoutChanged_hook() { 203 if ( layoutChanged_event.func ) { 204 typedef void (*func_type)(void *data); 205 (*(func_type)layoutChanged_event.func)(layoutChanged_event.data); 206 } 207 } layoutAboutToBeChanged_hook()208 void layoutAboutToBeChanged_hook() { 209 if ( layoutAboutToBeChanged_event.func ) { 210 typedef void (*func_type)(void *data); 211 (*(func_type)layoutAboutToBeChanged_event.func)(layoutAboutToBeChanged_event.data); 212 } 213 } rowsAboutToBeInserted_hook(const QModelIndex & parent,int first,int last)214 void rowsAboutToBeInserted_hook(const QModelIndex& parent, int first, int last) { 215 if ( rowsAboutToBeInserted_event.func ) { 216 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 217 (*(func_type)rowsAboutToBeInserted_event.func)(rowsAboutToBeInserted_event.data, (const QModelIndexH)&parent, first, last); 218 } 219 } rowsInserted_hook(const QModelIndex & parent,int first,int last)220 void rowsInserted_hook(const QModelIndex& parent, int first, int last) { 221 if ( rowsInserted_event.func ) { 222 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 223 (*(func_type)rowsInserted_event.func)(rowsInserted_event.data, (const QModelIndexH)&parent, first, last); 224 } 225 } rowsAboutToBeRemoved_hook(const QModelIndex & parent,int first,int last)226 void rowsAboutToBeRemoved_hook(const QModelIndex& parent, int first, int last) { 227 if ( rowsAboutToBeRemoved_event.func ) { 228 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 229 (*(func_type)rowsAboutToBeRemoved_event.func)(rowsAboutToBeRemoved_event.data, (const QModelIndexH)&parent, first, last); 230 } 231 } rowsRemoved_hook(const QModelIndex & parent,int first,int last)232 void rowsRemoved_hook(const QModelIndex& parent, int first, int last) { 233 if ( rowsRemoved_event.func ) { 234 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 235 (*(func_type)rowsRemoved_event.func)(rowsRemoved_event.data, (const QModelIndexH)&parent, first, last); 236 } 237 } columnsAboutToBeInserted_hook(const QModelIndex & parent,int first,int last)238 void columnsAboutToBeInserted_hook(const QModelIndex& parent, int first, int last) { 239 if ( columnsAboutToBeInserted_event.func ) { 240 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 241 (*(func_type)columnsAboutToBeInserted_event.func)(columnsAboutToBeInserted_event.data, (const QModelIndexH)&parent, first, last); 242 } 243 } columnsInserted_hook(const QModelIndex & parent,int first,int last)244 void columnsInserted_hook(const QModelIndex& parent, int first, int last) { 245 if ( columnsInserted_event.func ) { 246 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 247 (*(func_type)columnsInserted_event.func)(columnsInserted_event.data, (const QModelIndexH)&parent, first, last); 248 } 249 } columnsAboutToBeRemoved_hook(const QModelIndex & parent,int first,int last)250 void columnsAboutToBeRemoved_hook(const QModelIndex& parent, int first, int last) { 251 if ( columnsAboutToBeRemoved_event.func ) { 252 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 253 (*(func_type)columnsAboutToBeRemoved_event.func)(columnsAboutToBeRemoved_event.data, (const QModelIndexH)&parent, first, last); 254 } 255 } columnsRemoved_hook(const QModelIndex & parent,int first,int last)256 void columnsRemoved_hook(const QModelIndex& parent, int first, int last) { 257 if ( columnsRemoved_event.func ) { 258 typedef void (*func_type)(void *data, const QModelIndexH parent, int first, int last); 259 (*(func_type)columnsRemoved_event.func)(columnsRemoved_event.data, (const QModelIndexH)&parent, first, last); 260 } 261 } modelAboutToBeReset_hook()262 void modelAboutToBeReset_hook() { 263 if ( modelAboutToBeReset_event.func ) { 264 typedef void (*func_type)(void *data); 265 (*(func_type)modelAboutToBeReset_event.func)(modelAboutToBeReset_event.data); 266 } 267 } modelReset_hook()268 void modelReset_hook() { 269 if ( modelReset_event.func ) { 270 typedef void (*func_type)(void *data); 271 (*(func_type)modelReset_event.func)(modelReset_event.data); 272 } 273 } rowsAboutToBeMoved_hook(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destinationParent,int destinationRow)274 void rowsAboutToBeMoved_hook(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationRow) { 275 if ( rowsAboutToBeMoved_event.func ) { 276 typedef void (*func_type)(void *data, const QModelIndexH sourceParent, int sourceStart, int sourceEnd, const QModelIndexH destinationParent, int destinationRow); 277 (*(func_type)rowsAboutToBeMoved_event.func)(rowsAboutToBeMoved_event.data, (const QModelIndexH)&sourceParent, sourceStart, sourceEnd, (const QModelIndexH)&destinationParent, destinationRow); 278 } 279 } rowsMoved_hook(const QModelIndex & parent,int start,int end,const QModelIndex & destination,int row)280 void rowsMoved_hook(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int row) { 281 if ( rowsMoved_event.func ) { 282 typedef void (*func_type)(void *data, const QModelIndexH parent, int start, int end, const QModelIndexH destination, int row); 283 (*(func_type)rowsMoved_event.func)(rowsMoved_event.data, (const QModelIndexH)&parent, start, end, (const QModelIndexH)&destination, row); 284 } 285 } columnsAboutToBeMoved_hook(const QModelIndex & sourceParent,int sourceStart,int sourceEnd,const QModelIndex & destinationParent,int destinationColumn)286 void columnsAboutToBeMoved_hook(const QModelIndex& sourceParent, int sourceStart, int sourceEnd, const QModelIndex& destinationParent, int destinationColumn) { 287 if ( columnsAboutToBeMoved_event.func ) { 288 typedef void (*func_type)(void *data, const QModelIndexH sourceParent, int sourceStart, int sourceEnd, const QModelIndexH destinationParent, int destinationColumn); 289 (*(func_type)columnsAboutToBeMoved_event.func)(columnsAboutToBeMoved_event.data, (const QModelIndexH)&sourceParent, sourceStart, sourceEnd, (const QModelIndexH)&destinationParent, destinationColumn); 290 } 291 } columnsMoved_hook(const QModelIndex & parent,int start,int end,const QModelIndex & destination,int column)292 void columnsMoved_hook(const QModelIndex& parent, int start, int end, const QModelIndex& destination, int column) { 293 if ( columnsMoved_event.func ) { 294 typedef void (*func_type)(void *data, const QModelIndexH parent, int start, int end, const QModelIndexH destination, int column); 295 (*(func_type)columnsMoved_event.func)(columnsMoved_event.data, (const QModelIndexH)&parent, start, end, (const QModelIndexH)&destination, column); 296 } 297 } 298 private: 299 QHook dataChanged_event; 300 QHook headerDataChanged_event; 301 QHook layoutChanged_event; 302 QHook layoutAboutToBeChanged_event; 303 QHook rowsAboutToBeInserted_event; 304 QHook rowsInserted_event; 305 QHook rowsAboutToBeRemoved_event; 306 QHook rowsRemoved_event; 307 QHook columnsAboutToBeInserted_event; 308 QHook columnsInserted_event; 309 QHook columnsAboutToBeRemoved_event; 310 QHook columnsRemoved_event; 311 QHook modelAboutToBeReset_event; 312 QHook modelReset_event; 313 QHook rowsAboutToBeMoved_event; 314 QHook rowsMoved_event; 315 QHook columnsAboutToBeMoved_event; 316 QHook columnsMoved_event; 317 }; 318 319 320 #include "qabstractitemmodel_hook.h" 321 322 class QAbstractTableModel_hook : public QAbstractItemModel_hook { 323 Q_OBJECT 324 public: QAbstractTableModel_hook(QObject * handle)325 QAbstractTableModel_hook(QObject *handle) : QAbstractItemModel_hook(handle) { 326 } 327 }; 328 329 330 #include "qabstractitemmodel_hook.h" 331 332 class QAbstractListModel_hook : public QAbstractItemModel_hook { 333 Q_OBJECT 334 public: QAbstractListModel_hook(QObject * handle)335 QAbstractListModel_hook(QObject *handle) : QAbstractItemModel_hook(handle) { 336 } 337 }; 338 339 340 #endif 341