File indexing completed on 2024-04-21 03:42:36
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractListModel> 0010 #include <QDebug> 0011 0012 class SkyObject; 0013 0014 /** 0015 * @class SkyObjectListModel 0016 * A model used in Find Object Dialog in QML. Each entry is a QString (name of object) and pointer to 0017 * SkyObject itself 0018 * 0019 * @short Model that is used in Find Object Dialog 0020 * @author Artem Fedoskin, Jason Harris 0021 * @version 1.0 0022 */ 0023 class SkyObjectListModel : public QAbstractListModel 0024 { 0025 Q_OBJECT 0026 public: 0027 enum DemoRoles 0028 { 0029 SkyObjectRole = Qt::UserRole + 1, 0030 }; 0031 0032 explicit SkyObjectListModel(QObject *parent = nullptr); 0033 0034 int rowCount(const QModelIndex &) const override { return skyObjects.size(); } 0035 QVariant data(const QModelIndex &index, int role) const override; 0036 0037 QHash<int, QByteArray> roleNames() const override; 0038 0039 /** 0040 * @return index of object from skyObjects with name objectName. -1 if object with such 0041 * name was not found 0042 */ 0043 int indexOf(const QString &objectName) const; 0044 0045 /** 0046 * @short Filter the model 0047 * @param regEx Regex 0048 * @return Filtered string list 0049 */ 0050 QStringList filter(const QRegExp ®Ex); 0051 0052 void setSkyObjectsList(QVector<QPair<QString, const SkyObject *>> sObjects); 0053 0054 public slots: 0055 void removeSkyObject(SkyObject *object); 0056 0057 private: 0058 QVector<QPair<QString, const SkyObject *>> skyObjects; 0059 };