QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsquickmessagelogmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickmessagelogmodel.h
3  --------------------------------------
4  date : 13.7.2016
5  copyright : (C) 2016 by Matthias Kuhn
6  email : matthias (at) opengis.ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSQUICKMESSAGELOGMODEL_H
17 #define QGSQUICKMESSAGELOGMODEL_H
18 
19 #include <QAbstractListModel>
20 #include <QString>
21 #include <QVector>
22 
23 #include "qgis.h"
24 #include "qgsmessagelog.h"
25 
26 #include "qgis_quick.h"
27 
41 class QUICK_EXPORT QgsQuickMessageLogModel : public QAbstractListModel
42 {
43  Q_OBJECT
44 
45  struct LogMessage
46  {
47  LogMessage() = default;
48 
49  QString tag;
50  QString message;
51  Qgis::MessageLevel level;
52  };
53 
54  enum Roles
55  {
56  MessageRole = Qt::UserRole,
57  MessageTagRole,
58  MessageLevelRole
59  };
60 
61  public:
63  QgsQuickMessageLogModel( QObject *parent = nullptr );
64 
65  QHash<int, QByteArray> roleNames() const override;
66  int rowCount( const QModelIndex &parent ) const override;
67  QVariant data( const QModelIndex &index, int role ) const override;
68 
69  private slots:
70  void onMessageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level );
71 
72  private:
74  LogMessage logMessage( const QString &tag, const QString &message, Qgis::MessageLevel level );
75 
77  QVector<LogMessage> mMessages;
78 };
79 
80 #endif // QGSQUICKMESSAGELOGMODEL_H
This model will connect to the QgsMessageLog singleton and store any messages received.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78