WimaPolygonContainer.cc 1.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#include "WimaPolygonContainer.h"

WimaPolygonContainer::WimaPolygonContainer(QObject *parent) :
    QObject             (parent)
    ,_flatListDirty     (true)
{
    connect(this, &WimaPolygonContainer::itemListChanged, this, &WimaPolygonContainer::setFlatListDirty);
}

QList<WimaPolygon *> &WimaPolygonContainer::returnItems()
{
    return _itemList;
}

void WimaPolygonContainer::addItem(WimaPolygon *polygon)
{
    if(polygon != nullptr){
        _itemList.append(polygon);

        emit itemListChanged();
    }
    else {
        qWarning("Not a valid WimaPolygon!");
    }
}

void WimaPolygonContainer::removeItem(int itemIndex)
{
    if(itemIndex >= 0 && itemIndex < _itemList.count()){
        _itemList.removeAt(itemIndex);

        emit itemListChanged();
    }else {
        qWarning("Invalid item Index. Index must be in 0..%i.", _itemList.count()-1);
    }
}

void WimaPolygonContainer::removeItem(WimaPolygon *polygon)
{
    if(polygon != nullptr){
        _itemList.removeOne(polygon);

        emit itemListChanged();
    }
    else {
        qWarning("Not a valid WimaPolygon!");
    }
}

QList<WimaPolygon*>& WimaPolygonContainer::returnFlatList()
{
    if(_flatListDirty){
        _flatList.clear();

        int count = _itemList.count();
        for(int i = 0; i < count; i++){
            WimaPolygon* poly = _itemList.takeAt(i);
            _flatList.append(poly);
            _flatList.append(poly->subPolygons()); // returns an emptey list, if no sub polygons exist
        }
        _flatListDirty = false;
    }

    return _flatList;
}

67 68 69 70 71
int WimaPolygonContainer::count()
{
    return _itemList.size();
}

72 73 74 75
void WimaPolygonContainer::setFlatListDirty(void)
{
    _flatListDirty = true;
}