1 /*********************************************************************** 2 * 3 * Copyright (C) 2012, 2013 Graeme Gott <graeme@gottcode.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 ***********************************************************************/ 19 20 #ifndef SYMBOLS_MODEL_H 21 #define SYMBOLS_MODEL_H 22 23 #include <QAbstractListModel> 24 #include <QHash> 25 #include <QVector> 26 27 class SymbolsModel : public QAbstractItemModel 28 { 29 Q_OBJECT 30 31 private: 32 struct Filter 33 { 34 struct Range 35 { 36 quint32 start; 37 quint32 end; 38 }; 39 40 QByteArray name; 41 quint32 size; 42 QVector<Range> ranges; 43 }; 44 typedef QVector<Filter> FilterGroup; 45 46 public: 47 SymbolsModel(QObject* parent = 0); 48 49 QStringList filters(int group) const; 50 QStringList filterGroups() const; 51 void setFilter(int group, int index); 52 int symbolFilter(int group, quint32 unicode) const; 53 QString symbolName(quint32 unicode) const; 54 55 int columnCount(const QModelIndex& parent = QModelIndex()) const; 56 QVariant data(const QModelIndex& index, int role) const; 57 Qt::ItemFlags flags(const QModelIndex& index) const; 58 QModelIndex index(quint32 unicode) const; 59 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; 60 QModelIndex parent(const QModelIndex& child) const; 61 int rowCount(const QModelIndex& parent = QModelIndex()) const; 62 63 static void setData(const QStringList& datadirs); 64 65 friend QDataStream& operator>>(QDataStream& stream, SymbolsModel::Filter& filter); 66 friend QDataStream& operator>>(QDataStream& stream, SymbolsModel::Filter::Range& range); 67 68 private: 69 QVector<quint32> m_symbols; 70 71 QHash<quint32, QByteArray> m_names; 72 QVector<FilterGroup> m_groups; 73 74 static QString m_path; 75 }; 76 77 #endif 78