/**************************************************************************** * * (c) 2017 QGROUNDCONTROL PROJECT * * QGroundControl is licensed according to the terms in the file * COPYING.md in the root of the source code directory. * ****************************************************************************/ #include "AirspaceFlightPlanProvider.h" #include //----------------------------------------------------------------------------- AirspaceFlightInfo::AirspaceFlightInfo(QObject *parent) : QObject(parent) , _selected(false) { } //----------------------------------------------------------------------------- AirspaceFlightPlanProvider::AirspaceFlightPlanProvider(QObject *parent) : QObject(parent) { } //----------------------------------------------------------------------------- AirspaceFlightModel::AirspaceFlightModel(QObject *parent) : QAbstractListModel(parent) { } //----------------------------------------------------------------------------- AirspaceFlightInfo* AirspaceFlightModel::get(int index) { if (index < 0 || index >= _flightEntries.count()) { return NULL; } return _flightEntries[index]; } //----------------------------------------------------------------------------- int AirspaceFlightModel::count() const { return _flightEntries.count(); } //----------------------------------------------------------------------------- void AirspaceFlightModel::append(AirspaceFlightInfo* object) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); _flightEntries.append(object); endInsertRows(); emit countChanged(); } //----------------------------------------------------------------------------- void AirspaceFlightModel::clear(void) { if(!_flightEntries.isEmpty()) { beginRemoveRows(QModelIndex(), 0, _flightEntries.count()); while (_flightEntries.count()) { AirspaceFlightInfo* entry = _flightEntries.last(); if(entry) entry->deleteLater(); _flightEntries.removeLast(); } endRemoveRows(); emit countChanged(); } } //----------------------------------------------------------------------------- AirspaceFlightInfo* AirspaceFlightModel::operator[](int index) { return get(index); } //----------------------------------------------------------------------------- int AirspaceFlightModel::rowCount(const QModelIndex& /*parent*/) const { return _flightEntries.count(); } //----------------------------------------------------------------------------- QVariant AirspaceFlightModel::data(const QModelIndex & index, int role) const { if (index.row() < 0 || index.row() >= _flightEntries.count()) return QVariant(); if (role == ObjectRole) return QVariant::fromValue(_flightEntries[index.row()]); return QVariant(); } //----------------------------------------------------------------------------- QHash AirspaceFlightModel::roleNames() const { QHash roles; roles[ObjectRole] = "flightEntry"; return roles; }