File indexing completed on 2025-01-26 05:06:09
0001 /* 0002 SPDX-FileCopyrightText: 2012 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KACTIVITIES_MODEL_UPDATERS_H 0008 #define KACTIVITIES_MODEL_UPDATERS_H 0009 0010 // ----------------------------------------- 0011 // RAII classes for model updates ---------- 0012 // ----------------------------------------- 0013 0014 // clang-format off 0015 #define DECLARE_RAII_MODEL_UPDATERS(Class) \ 0016 template <typename T> class _model_reset { \ 0017 T *model; \ 0018 \ 0019 public: \ 0020 _model_reset(T *m) : model(m) \ 0021 { \ 0022 model->beginResetModel(); \ 0023 } \ 0024 ~_model_reset() \ 0025 { \ 0026 model->endResetModel(); \ 0027 } \ 0028 }; \ 0029 template <typename T> class _model_insert { \ 0030 T *model; \ 0031 \ 0032 public: \ 0033 _model_insert(T *m, const QModelIndex &parent, int first, int last) \ 0034 : model(m) \ 0035 { \ 0036 model->beginInsertRows(parent, first, last); \ 0037 } \ 0038 ~_model_insert() \ 0039 { \ 0040 model->endInsertRows(); \ 0041 } \ 0042 }; \ 0043 template <typename T> class _model_remove { \ 0044 T *model; \ 0045 \ 0046 public: \ 0047 _model_remove(T *m, const QModelIndex &parent, int first, int last) \ 0048 : model(m) \ 0049 { \ 0050 model->beginRemoveRows(parent, first, last); \ 0051 } \ 0052 ~_model_remove() \ 0053 { \ 0054 model->endRemoveRows(); \ 0055 } \ 0056 }; \ 0057 typedef _model_reset<Class> model_reset; \ 0058 typedef _model_remove<Class> model_remove; \ 0059 typedef _model_insert<Class> model_insert; 0060 0061 // ----------------------------------------- 0062 0063 #endif // KACTIVITIES_MODEL_UPDATERS_H 0064