def testIsNumericRole(self):
        m = QgsPointCloudAttributeModel()
        m.setAttributes(create_attributes())

        self.assertTrue(
            m.data(m.index(0, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(1, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(2, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertFalse(
            m.data(m.index(3, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(4, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertFalse(
            m.data(m.index(5, 0), QgsPointCloudAttributeModel.IsNumericRole))
        m.setAllowEmptyAttributeName(True)
        self.assertFalse(
            m.data(m.index(0, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(1, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(2, 0), QgsPointCloudAttributeModel.IsNumericRole))
        self.assertTrue(
            m.data(m.index(5, 0), QgsPointCloudAttributeModel.IsNumericRole))
    def testAttributeNameRole(self):
        m = QgsPointCloudAttributeModel()
        m.setAttributes(create_attributes())

        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'z')
        self.assertEqual(
            m.data(m.index(3, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'cat')
        self.assertEqual(
            m.data(m.index(4, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeNameRole), 'red')
    def testAttributeIndexRole(self):
        m = QgsPointCloudAttributeModel()
        m.setAttributes(create_attributes())

        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 0)
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 1)
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 2)
        self.assertEqual(
            m.data(m.index(3, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 3)
        self.assertEqual(
            m.data(m.index(4, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 4)
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), None)
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 0)
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 1)
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeIndexRole), 4)
 def testRowCount(self):
     m = QgsPointCloudAttributeModel()
     self.assertEqual(m.rowCount(), 0)
     m.setAttributes(create_attributes())
     self.assertEqual(m.rowCount(), 5)
     m.setAllowEmptyAttributeName(True)
     self.assertEqual(m.rowCount(), 6)
     m.setAllowEmptyAttributeName(False)
     self.assertEqual(m.rowCount(), 5)
    def testGettersSetters(self):
        """ test model getters/setters """
        m = QgsPointCloudAttributeModel()
        self.assertEqual(m.attributes().count(), 0)

        m.setAllowEmptyAttributeName(True)
        self.assertTrue(m.allowEmptyAttributeName())
        m.setAllowEmptyAttributeName(False)
        self.assertFalse(m.allowEmptyAttributeName())

        attributes = create_attributes()
        m.setAttributes(attributes)
        self.assertEqual([a.name() for a in m.attributes().attributes()],
                         ['x', 'y', 'z', 'cat', 'red'])
    def testTypeRole(self):
        m = QgsPointCloudAttributeModel()
        m.setAttributes(create_attributes())

        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Float)
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Float)
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Float)
        self.assertEqual(
            m.data(m.index(3, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Char)
        self.assertEqual(
            m.data(m.index(4, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Int32)
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(
            m.data(m.index(0, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole), None)
        self.assertEqual(
            m.data(m.index(1, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Float)
        self.assertEqual(
            m.data(m.index(2, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Float)
        self.assertEqual(
            m.data(m.index(5, 0),
                   QgsPointCloudAttributeModel.AttributeTypeRole),
            QgsPointCloudAttribute.Int32)
    def testTooltip(self):
        m = QgsPointCloudAttributeModel()
        m.setAttributes(create_attributes())

        self.assertEqual(
            m.data(m.index(0, 0), Qt.ToolTipRole),
            "<b>x</b><br><font style='font-family:monospace; white-space: nowrap;'>Float</font>"
        )
        self.assertEqual(
            m.data(m.index(1, 0), Qt.ToolTipRole),
            "<b>y</b><br><font style='font-family:monospace; white-space: nowrap;'>Float</font>"
        )
        self.assertEqual(
            m.data(m.index(2, 0), Qt.ToolTipRole),
            "<b>z</b><br><font style='font-family:monospace; white-space: nowrap;'>Float</font>"
        )
        self.assertEqual(
            m.data(m.index(3, 0), Qt.ToolTipRole),
            "<b>cat</b><br><font style='font-family:monospace; white-space: nowrap;'>Character</font>"
        )
        self.assertEqual(
            m.data(m.index(4, 0), Qt.ToolTipRole),
            "<b>red</b><br><font style='font-family:monospace; white-space: nowrap;'>Integer</font>"
        )
        self.assertEqual(m.data(m.index(5, 0), Qt.ToolTipRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(m.data(m.index(0, 0), Qt.ToolTipRole), None)
        self.assertEqual(
            m.data(m.index(1, 0), Qt.ToolTipRole),
            "<b>x</b><br><font style='font-family:monospace; white-space: nowrap;'>Float</font>"
        )
        self.assertEqual(
            m.data(m.index(2, 0), Qt.ToolTipRole),
            "<b>y</b><br><font style='font-family:monospace; white-space: nowrap;'>Float</font>"
        )
        self.assertEqual(
            m.data(m.index(5, 0), Qt.ToolTipRole),
            "<b>red</b><br><font style='font-family:monospace; white-space: nowrap;'>Integer</font>"
        )
    def testIndexFromName(self):
        m = QgsPointCloudAttributeModel()

        i = m.indexFromName('fldtxt')
        self.assertFalse(i.isValid())

        m.setAttributes(create_attributes())
        i = m.indexFromName('fldtxt')
        self.assertFalse(i.isValid())
        i = m.indexFromName('y')
        self.assertTrue(i.isValid())
        self.assertEqual(i.row(), 1)
        i = m.indexFromName('')
        self.assertFalse(i.isValid())

        m.setAllowEmptyAttributeName(True)
        i = m.indexFromName('fldtxt')
        self.assertFalse(i.isValid())
        i = m.indexFromName('y')
        self.assertTrue(i.isValid())
        self.assertEqual(i.row(), 2)
        i = m.indexFromName('')
        self.assertTrue(i.isValid())
        self.assertEqual(i.row(), 0)
    def testProxyModel(self):
        m = QgsPointCloudAttributeModel()
        attributes = create_attributes()
        attributes.push_back(
            QgsPointCloudAttribute('green', QgsPointCloudAttribute.Short))
        attributes.push_back(
            QgsPointCloudAttribute('intensity', QgsPointCloudAttribute.Double))
        m.setAttributes(attributes)
        proxy = QgsPointCloudAttributeProxyModel(m)

        self.assertEqual(proxy.rowCount(), 7)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'z')
        self.assertEqual(
            proxy.data(proxy.index(3, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'cat')
        self.assertEqual(
            proxy.data(proxy.index(4, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(5, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'green')
        self.assertEqual(
            proxy.data(proxy.index(6, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')
        self.assertEqual(
            proxy.data(proxy.index(7, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 8)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(7, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Char)
        self.assertEqual(proxy.rowCount(), 1)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'cat')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 2)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'cat')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Short)
        self.assertEqual(proxy.rowCount(), 1)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'green')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 2)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'green')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Int32)
        self.assertEqual(proxy.rowCount(), 1)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 2)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Float)
        self.assertEqual(proxy.rowCount(), 3)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'z')
        self.assertEqual(
            proxy.data(proxy.index(3, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 4)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(3, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'z')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Double)
        self.assertEqual(proxy.rowCount(), 1)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 2)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Double
                         | QgsPointCloudAttributeProxyModel.Int32)
        self.assertEqual(proxy.rowCount(), 2)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 3)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')

        m.setAllowEmptyAttributeName(False)
        proxy.setFilters(QgsPointCloudAttributeProxyModel.Numeric)
        self.assertEqual(proxy.rowCount(), 6)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'z')
        self.assertEqual(
            proxy.data(proxy.index(3, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(4, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'green')
        self.assertEqual(
            proxy.data(proxy.index(5, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')
        self.assertEqual(
            proxy.data(proxy.index(6, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        m.setAllowEmptyAttributeName(True)
        self.assertEqual(proxy.rowCount(), 7)
        self.assertEqual(
            proxy.data(proxy.index(0, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), None)
        self.assertEqual(
            proxy.data(proxy.index(1, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'x')
        self.assertEqual(
            proxy.data(proxy.index(2, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'y')
        self.assertEqual(
            proxy.data(proxy.index(3, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'z')
        self.assertEqual(
            proxy.data(proxy.index(4, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'red')
        self.assertEqual(
            proxy.data(proxy.index(5, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole), 'green')
        self.assertEqual(
            proxy.data(proxy.index(6, 0),
                       QgsPointCloudAttributeModel.AttributeNameRole),
            'intensity')