| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qundoview.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | class QUndoModel : public QAbstractItemModel | - | ||||||||||||
| 8 | { | - | ||||||||||||
| 9 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 10 | #pragma GCC diagnostic push | - | ||||||||||||
| 11 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 12 | #pragma GCC diagnostic pop | - | ||||||||||||
| 13 | struct QPrivateSignal {}; | - | ||||||||||||
| 14 | public: | - | ||||||||||||
| 15 | QUndoModel(QObject *parent = 0); | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | QUndoStack *stack() const; | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | virtual QModelIndex index(int row, int column, | - | ||||||||||||
| 20 | const QModelIndex &parent = QModelIndex()) const override; | - | ||||||||||||
| 21 | virtual QModelIndex parent(const QModelIndex &child) const override; | - | ||||||||||||
| 22 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; | - | ||||||||||||
| 23 | virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; | - | ||||||||||||
| 24 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | - | ||||||||||||
| 25 | - | |||||||||||||
| 26 | QModelIndex selectedIndex() const; | - | ||||||||||||
| 27 | QItemSelectionModel *selectionModel() const; | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | QString emptyLabel() const; | - | ||||||||||||
| 30 | void setEmptyLabel(const QString &label); | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | void setCleanIcon(const QIcon &icon); | - | ||||||||||||
| 33 | QIcon cleanIcon() const; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | public : | - | ||||||||||||
| 36 | void setStack(QUndoStack *stack); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | private : | - | ||||||||||||
| 39 | void stackChanged(); | - | ||||||||||||
| 40 | void stackDestroyed(QObject *obj); | - | ||||||||||||
| 41 | void setStackCurrentIndex(const QModelIndex &index); | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | private: | - | ||||||||||||
| 44 | QUndoStack *m_stack; | - | ||||||||||||
| 45 | QItemSelectionModel *m_sel_model; | - | ||||||||||||
| 46 | QString m_emty_label; | - | ||||||||||||
| 47 | QIcon m_clean_icon; | - | ||||||||||||
| 48 | }; | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | QUndoModel::QUndoModel(QObject *parent) | - | ||||||||||||
| 51 | : QAbstractItemModel(parent) | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | m_stack = 0; | - | ||||||||||||
| 54 | m_sel_model = new QItemSelectionModel(this, this); | - | ||||||||||||
| 55 | connect(m_sel_model, qFlagLocation("2""currentChanged(QModelIndex,QModelIndex)" "\0" __FILE__ ":" "97"), | - | ||||||||||||
| 56 | this, qFlagLocation("1""setStackCurrentIndex(QModelIndex)" "\0" __FILE__ ":" "98")); | - | ||||||||||||
| 57 | m_emty_label = tr("<empty>"); | - | ||||||||||||
| 58 | } never executed: end of block | 0 | ||||||||||||
| 59 | - | |||||||||||||
| 60 | QItemSelectionModel *QUndoModel::selectionModel() const | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | return never executed: m_sel_model;return m_sel_model;never executed: return m_sel_model; | 0 | ||||||||||||
| 63 | } | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | QUndoStack *QUndoModel::stack() const | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | return never executed: m_stack;return m_stack;never executed: return m_stack; | 0 | ||||||||||||
| 68 | } | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | void QUndoModel::setStack(QUndoStack *stack) | - | ||||||||||||
| 71 | { | - | ||||||||||||
| 72 | if (m_stack == stack
| 0 | ||||||||||||
| 73 | return; never executed: return; | 0 | ||||||||||||
| 74 | - | |||||||||||||
| 75 | if (m_stack != 0
| 0 | ||||||||||||
| 76 | disconnect(m_stack, qFlagLocation("2""cleanChanged(bool)" "\0" __FILE__ ":" "118"), this, qFlagLocation("1""stackChanged()" "\0" __FILE__ ":" "118")); | - | ||||||||||||
| 77 | disconnect(m_stack, qFlagLocation("2""indexChanged(int)" "\0" __FILE__ ":" "119"), this, qFlagLocation("1""stackChanged()" "\0" __FILE__ ":" "119")); | - | ||||||||||||
| 78 | disconnect(m_stack, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "120"), this, qFlagLocation("1""stackDestroyed(QObject*)" "\0" __FILE__ ":" "120")); | - | ||||||||||||
| 79 | } never executed: end of block | 0 | ||||||||||||
| 80 | m_stack = stack; | - | ||||||||||||
| 81 | if (m_stack != 0
| 0 | ||||||||||||
| 82 | connect(m_stack, qFlagLocation("2""cleanChanged(bool)" "\0" __FILE__ ":" "124"), this, qFlagLocation("1""stackChanged()" "\0" __FILE__ ":" "124")); | - | ||||||||||||
| 83 | connect(m_stack, qFlagLocation("2""indexChanged(int)" "\0" __FILE__ ":" "125"), this, qFlagLocation("1""stackChanged()" "\0" __FILE__ ":" "125")); | - | ||||||||||||
| 84 | connect(m_stack, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "126"), this, qFlagLocation("1""stackDestroyed(QObject*)" "\0" __FILE__ ":" "126")); | - | ||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | stackChanged(); | - | ||||||||||||
| 88 | } never executed: end of block | 0 | ||||||||||||
| 89 | - | |||||||||||||
| 90 | void QUndoModel::stackDestroyed(QObject *obj) | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | if (obj != m_stack
| 0 | ||||||||||||
| 93 | return; never executed: return; | 0 | ||||||||||||
| 94 | m_stack = 0; | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | stackChanged(); | - | ||||||||||||
| 97 | } never executed: end of block | 0 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | void QUndoModel::stackChanged() | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | beginResetModel(); | - | ||||||||||||
| 102 | endResetModel(); | - | ||||||||||||
| 103 | m_sel_model->setCurrentIndex(selectedIndex(), QItemSelectionModel::ClearAndSelect); | - | ||||||||||||
| 104 | } never executed: end of block | 0 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | void QUndoModel::setStackCurrentIndex(const QModelIndex &index) | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | if (m_stack == 0
| 0 | ||||||||||||
| 109 | return; never executed: return; | 0 | ||||||||||||
| 110 | - | |||||||||||||
| 111 | if (index == selectedIndex()
| 0 | ||||||||||||
| 112 | return; never executed: return; | 0 | ||||||||||||
| 113 | - | |||||||||||||
| 114 | if (index.column() != 0
| 0 | ||||||||||||
| 115 | return; never executed: return; | 0 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | m_stack->setIndex(index.row()); | - | ||||||||||||
| 118 | } never executed: end of block | 0 | ||||||||||||
| 119 | - | |||||||||||||
| 120 | QModelIndex QUndoModel::selectedIndex() const | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | return never executed: m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0);return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0);never executed: return m_stack == 0 ? QModelIndex() : createIndex(m_stack->index(), 0); | 0 | ||||||||||||
| 123 | } | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | QModelIndex QUndoModel::index(int row, int column, const QModelIndex &parent) const | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | if (m_stack == 0
| 0 | ||||||||||||
| 128 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||
| 129 | - | |||||||||||||
| 130 | if (parent.isValid()
| 0 | ||||||||||||
| 131 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | if (column != 0
| 0 | ||||||||||||
| 134 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | if (row < 0
| 0 | ||||||||||||
| 137 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||
| 138 | - | |||||||||||||
| 139 | return never executed: createIndex(row, column);return createIndex(row, column);never executed: return createIndex(row, column); | 0 | ||||||||||||
| 140 | } | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | QModelIndex QUndoModel::parent(const QModelIndex&) const | - | ||||||||||||
| 143 | { | - | ||||||||||||
| 144 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||
| 145 | } | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | int QUndoModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||
| 148 | { | - | ||||||||||||
| 149 | if (m_stack == 0
| 0 | ||||||||||||
| 150 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 151 | - | |||||||||||||
| 152 | if (parent.isValid()
| 0 | ||||||||||||
| 153 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 154 | - | |||||||||||||
| 155 | return never executed: m_stack->count() + 1;return m_stack->count() + 1;never executed: return m_stack->count() + 1; | 0 | ||||||||||||
| 156 | } | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | int QUndoModel::columnCount(const QModelIndex&) const | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | QVariant QUndoModel::data(const QModelIndex &index, int role) const | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | if (m_stack == 0
| 0 | ||||||||||||
| 166 | return never executed: QVariant();return QVariant();never executed: return QVariant(); | 0 | ||||||||||||
| 167 | - | |||||||||||||
| 168 | if (index.column() != 0
| 0 | ||||||||||||
| 169 | return never executed: QVariant();return QVariant();never executed: return QVariant(); | 0 | ||||||||||||
| 170 | - | |||||||||||||
| 171 | if (index.row() < 0
| 0 | ||||||||||||
| 172 | return never executed: QVariant();return QVariant();never executed: return QVariant(); | 0 | ||||||||||||
| 173 | - | |||||||||||||
| 174 | if (role == Qt::DisplayRole
| 0 | ||||||||||||
| 175 | if (index.row() == 0
| 0 | ||||||||||||
| 176 | return never executed: m_emty_label;return m_emty_label;never executed: return m_emty_label; | 0 | ||||||||||||
| 177 | return never executed: m_stack->text(index.row() - 1);return m_stack->text(index.row() - 1);never executed: return m_stack->text(index.row() - 1); | 0 | ||||||||||||
| 178 | } else if (role == Qt::DecorationRole
| 0 | ||||||||||||
| 179 | if (index.row() == m_stack->cleanIndex()
| 0 | ||||||||||||
| 180 | return never executed: m_clean_icon;return m_clean_icon;never executed: return m_clean_icon; | 0 | ||||||||||||
| 181 | return never executed: QVariant();return QVariant();never executed: return QVariant(); | 0 | ||||||||||||
| 182 | } | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | return never executed: QVariant();return QVariant();never executed: return QVariant(); | 0 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | QString QUndoModel::emptyLabel() const | - | ||||||||||||
| 188 | { | - | ||||||||||||
| 189 | return never executed: m_emty_label;return m_emty_label;never executed: return m_emty_label; | 0 | ||||||||||||
| 190 | } | - | ||||||||||||
| 191 | - | |||||||||||||
| 192 | void QUndoModel::setEmptyLabel(const QString &label) | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | m_emty_label = label; | - | ||||||||||||
| 195 | stackChanged(); | - | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | void QUndoModel::setCleanIcon(const QIcon &icon) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | m_clean_icon = icon; | - | ||||||||||||
| 201 | stackChanged(); | - | ||||||||||||
| 202 | } never executed: end of block | 0 | ||||||||||||
| 203 | - | |||||||||||||
| 204 | QIcon QUndoModel::cleanIcon() const | - | ||||||||||||
| 205 | { | - | ||||||||||||
| 206 | return never executed: m_clean_icon;return m_clean_icon;never executed: return m_clean_icon; | 0 | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | class QUndoViewPrivate : public QListViewPrivate | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | inline QUndoView* q_func() { return static_cast<QUndoView *>(q_ptr); } inline const QUndoView* q_func() const { return static_cast<const QUndoView *>(q_ptr); } friend class QUndoView; | - | ||||||||||||
| 211 | public: | - | ||||||||||||
| 212 | QUndoViewPrivate() : | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | group(0), | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | model(0) {} never executed: end of block | 0 | ||||||||||||
| 217 | - | |||||||||||||
| 218 | - | |||||||||||||
| 219 | QPointer<QUndoGroup> group; | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | QUndoModel *model; | - | ||||||||||||
| 222 | - | |||||||||||||
| 223 | void init(); | - | ||||||||||||
| 224 | }; | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | void QUndoViewPrivate::init() | - | ||||||||||||
| 227 | { | - | ||||||||||||
| 228 | QUndoView * const q = q_func(); | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | model = new QUndoModel(q); | - | ||||||||||||
| 231 | q->setModel(model); | - | ||||||||||||
| 232 | q->setSelectionModel(model->selectionModel()); | - | ||||||||||||
| 233 | } never executed: end of block | 0 | ||||||||||||
| 234 | - | |||||||||||||
| 235 | - | |||||||||||||
| 236 | - | |||||||||||||
| 237 | - | |||||||||||||
| 238 | - | |||||||||||||
| 239 | QUndoView::QUndoView(QWidget *parent) | - | ||||||||||||
| 240 | : QListView(*new QUndoViewPrivate(), parent) | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 243 | d->init(); | - | ||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||
| 245 | - | |||||||||||||
| 246 | - | |||||||||||||
| 247 | - | |||||||||||||
| 248 | - | |||||||||||||
| 249 | - | |||||||||||||
| 250 | QUndoView::QUndoView(QUndoStack *stack, QWidget *parent) | - | ||||||||||||
| 251 | : QListView(*new QUndoViewPrivate(), parent) | - | ||||||||||||
| 252 | { | - | ||||||||||||
| 253 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 254 | d->init(); | - | ||||||||||||
| 255 | setStack(stack); | - | ||||||||||||
| 256 | } never executed: end of block | 0 | ||||||||||||
| 257 | QUndoView::QUndoView(QUndoGroup *group, QWidget *parent) | - | ||||||||||||
| 258 | : QListView(*new QUndoViewPrivate(), parent) | - | ||||||||||||
| 259 | { | - | ||||||||||||
| 260 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 261 | d->init(); | - | ||||||||||||
| 262 | setGroup(group); | - | ||||||||||||
| 263 | } never executed: end of block | 0 | ||||||||||||
| 264 | - | |||||||||||||
| 265 | - | |||||||||||||
| 266 | - | |||||||||||||
| 267 | - | |||||||||||||
| 268 | - | |||||||||||||
| 269 | - | |||||||||||||
| 270 | - | |||||||||||||
| 271 | QUndoView::~QUndoView() | - | ||||||||||||
| 272 | { | - | ||||||||||||
| 273 | } | - | ||||||||||||
| 274 | QUndoStack *QUndoView::stack() const | - | ||||||||||||
| 275 | { | - | ||||||||||||
| 276 | const QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 277 | return never executed: d->model->stack();return d->model->stack();never executed: return d->model->stack(); | 0 | ||||||||||||
| 278 | } | - | ||||||||||||
| 279 | void QUndoView::setStack(QUndoStack *stack) | - | ||||||||||||
| 280 | { | - | ||||||||||||
| 281 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 282 | - | |||||||||||||
| 283 | setGroup(0); | - | ||||||||||||
| 284 | - | |||||||||||||
| 285 | d->model->setStack(stack); | - | ||||||||||||
| 286 | } never executed: end of block | 0 | ||||||||||||
| 287 | void QUndoView::setGroup(QUndoGroup *group) | - | ||||||||||||
| 288 | { | - | ||||||||||||
| 289 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | if (d->group == group
| 0 | ||||||||||||
| 292 | return; never executed: return; | 0 | ||||||||||||
| 293 | - | |||||||||||||
| 294 | if (d->group != 0
| 0 | ||||||||||||
| 295 | disconnect(d->group, qFlagLocation("2""activeStackChanged(QUndoStack*)" "\0" __FILE__ ":" "397"), | - | ||||||||||||
| 296 | d->model, qFlagLocation("1""setStack(QUndoStack*)" "\0" __FILE__ ":" "398")); | - | ||||||||||||
| 297 | } never executed: end of block | 0 | ||||||||||||
| 298 | - | |||||||||||||
| 299 | d->group = group; | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | if (d->group != 0
| 0 | ||||||||||||
| 302 | connect(d->group, qFlagLocation("2""activeStackChanged(QUndoStack*)" "\0" __FILE__ ":" "404"), | - | ||||||||||||
| 303 | d->model, qFlagLocation("1""setStack(QUndoStack*)" "\0" __FILE__ ":" "405")); | - | ||||||||||||
| 304 | d->model->setStack(d->group->activeStack()); | - | ||||||||||||
| 305 | } never executed: else {end of block | 0 | ||||||||||||
| 306 | d->model->setStack(0); | - | ||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||
| 308 | } | - | ||||||||||||
| 309 | QUndoGroup *QUndoView::group() const | - | ||||||||||||
| 310 | { | - | ||||||||||||
| 311 | const QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 312 | return never executed: d->group;return d->group;never executed: return d->group; | 0 | ||||||||||||
| 313 | } | - | ||||||||||||
| 314 | void QUndoView::setEmptyLabel(const QString &label) | - | ||||||||||||
| 315 | { | - | ||||||||||||
| 316 | QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 317 | d->model->setEmptyLabel(label); | - | ||||||||||||
| 318 | } never executed: end of block | 0 | ||||||||||||
| 319 | - | |||||||||||||
| 320 | QString QUndoView::emptyLabel() const | - | ||||||||||||
| 321 | { | - | ||||||||||||
| 322 | const QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 323 | return never executed: d->model->emptyLabel();return d->model->emptyLabel();never executed: return d->model->emptyLabel(); | 0 | ||||||||||||
| 324 | } | - | ||||||||||||
| 325 | void QUndoView::setCleanIcon(const QIcon &icon) | - | ||||||||||||
| 326 | { | - | ||||||||||||
| 327 | const QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 328 | d->model->setCleanIcon(icon); | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 | } never executed: end of block | 0 | ||||||||||||
| 331 | - | |||||||||||||
| 332 | QIcon QUndoView::cleanIcon() const | - | ||||||||||||
| 333 | { | - | ||||||||||||
| 334 | const QUndoViewPrivate * const d = d_func(); | - | ||||||||||||
| 335 | return never executed: d->model->cleanIcon();return d->model->cleanIcon();never executed: return d->model->cleanIcon(); | 0 | ||||||||||||
| 336 | } | - | ||||||||||||
| 337 | - | |||||||||||||
| 338 | - | |||||||||||||
| 339 | - | |||||||||||||
| Switch to Source code | Preprocessed file |