# -*- coding: utf-8 -*-
"""
Copyright (c) 2016 Biuro Urządzania Lasu i Geodezji Leśnej

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
OTHER DEALINGS IN THE SOFTWARE.
"""


from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
from Mapa_PU.kontroler import komunikaty

"""Model obiektów podstawowych"""
class ObiektyPodstawoweModel(QAbstractTableModel):
    """Model obiektów podstawowych"""
    #Marcin Śliwa
    def __init__(self,dane,naglowki,rodzic=None,*arg):
        """Konstruktor"""
        QAbstractTableModel.__init__(self, rodzic, *arg)
        self.dane=dane
        self.naglowki=naglowki
         
    def rowCount(self, rodzic):
        """liczba wierszy
        :param rodzic: obiekt nadrzedny
        :return liczba wierszy
        """ 
        return len(self.dane) 
 
    def columnCount(self, rodzic):
        """liczba kolumn
        :param rodzic: obiekt nadrzedny
        :return liczba kolumn
        """ 
        return len(self.dane[0]) 
 
    def data(self, index, role):
        """Wyswietlanie danych
        :param index: nr wiersza
        :param role: rola
        :return dana
        """
        try:
          
            if role==Qt.DisplayRole: 
                return self.dane[index.row()][index.column()]
        except Exception as e:
            komunikaty.blad_systemowy(e)

    def headerData(self, col, orientation, role):
        """nagłówki mwidoku
        :param col:kolukmna
        :param orientation:orientacja 
        :param role:rola
        :return nagłówki
        """
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.naglowki[col]
        else:
            return QAbstractTableModel.headerData(self,col, orientation, role)
        
    def removeRows(self, row, rows=1, index=QModelIndex()):
        """Usunięcie wiersza z listy
        :param row: wiersz
        :param rows: liczba wierszy
        :param index: obiekt indeks
        """
        try:
            self.beginRemoveRows(QModelIndex(), row, row + rows - 1)
            self.dane = self.dane[:row] + self.dane[row + rows:]
            self.endRemoveRows()
            return True
        except Exception as e:
            komunikaty.blad_systemowy(e)
    
