-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a simple heat risk list model
- Loading branch information
1 parent
1821105
commit 117d428
Showing
8 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
native-apps/urban-heat-analyzer/UrbanHeatAnalyzer/HeatRiskListModel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// "Urban Heat Analyzer" | ||
// Copyright (C) 2024 Esri Deutschland GmbH | ||
// Jan Tschada (j.tschada@esri.de) | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
// | ||
// Additional permission under GNU GPL version 3 section 7 | ||
// | ||
// If you modify this Program, or any covered work, by linking or combining | ||
// it with ArcGIS Maps SDK for Qt (or a modified version of that library), | ||
// containing parts covered by the terms of ArcGIS Maps SDK for Qt, | ||
// the licensors of this Program grant you additional permission to convey the resulting work. | ||
// See <https://developers.arcgis.com/qt/> for further information. | ||
|
||
#include "HeatRiskListModel.h" | ||
|
||
#include "AttributeListModel.h" | ||
#include "Feature.h" | ||
|
||
using namespace Esri::ArcGISRuntime; | ||
|
||
|
||
HeatRiskAnalysisGroup::HeatRiskAnalysisGroup(double heatRiskIndex) | ||
: m_heatRiskIndex(heatRiskIndex) | ||
{ | ||
|
||
} | ||
|
||
QString HeatRiskAnalysisGroup::name() const | ||
{ | ||
if (m_heatRiskFeatures.empty()) | ||
{ | ||
return "Unknown"; | ||
} | ||
|
||
auto heatRiskFeatureAttributes = m_heatRiskFeatures.first()->attributes(); | ||
return heatRiskFeatureAttributes->attributeValue("GRID_ID").toString(); | ||
} | ||
|
||
double HeatRiskAnalysisGroup::heatRiskIndex() const | ||
{ | ||
return m_heatRiskIndex; | ||
} | ||
|
||
void HeatRiskAnalysisGroup::addFeature(Feature *heatRiskFeature) | ||
{ | ||
m_heatRiskFeatures.append(heatRiskFeature); | ||
} | ||
|
||
|
||
HeatRiskListModel::HeatRiskListModel(QObject *parent) | ||
: QAbstractListModel{parent} | ||
{ | ||
|
||
} | ||
|
||
void HeatRiskListModel::loadAnalysisGroups(const QList<HeatRiskAnalysisGroup> &analysisGroups) | ||
{ | ||
beginResetModel(); | ||
m_analysisGroups = analysisGroups; | ||
endResetModel(); | ||
|
||
// Emit that the full data has changed | ||
emit dataChanged(index(0,0), index(rowCount() - 1)); | ||
} | ||
|
||
int HeatRiskListModel::rowCount(const QModelIndex & parent) const { | ||
Q_UNUSED(parent); | ||
return m_analysisGroups.count(); | ||
} | ||
|
||
QVariant HeatRiskListModel::data(const QModelIndex & index, int role) const { | ||
if (index.row() < 0 || index.row() >= m_analysisGroups.count()) | ||
return QVariant(); | ||
|
||
const HeatRiskAnalysisGroup &analysisGroup = m_analysisGroups[index.row()]; | ||
if (role == NameRole) | ||
return analysisGroup.name(); | ||
else if (role == RiskRole) | ||
return analysisGroup.heatRiskIndex(); | ||
return QVariant(); | ||
} | ||
|
||
QHash<int, QByteArray> HeatRiskListModel::roleNames() const { | ||
QHash<int, QByteArray> roles; | ||
roles[NameRole] = "name"; | ||
roles[RiskRole] = "risk"; | ||
return roles; | ||
} |
65 changes: 65 additions & 0 deletions
65
native-apps/urban-heat-analyzer/UrbanHeatAnalyzer/HeatRiskListModel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// "Urban Heat Analyzer" | ||
// Copyright (C) 2024 Esri Deutschland GmbH | ||
// Jan Tschada (j.tschada@esri.de) | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
// | ||
// Additional permission under GNU GPL version 3 section 7 | ||
// | ||
// If you modify this Program, or any covered work, by linking or combining | ||
// it with ArcGIS Maps SDK for Qt (or a modified version of that library), | ||
// containing parts covered by the terms of ArcGIS Maps SDK for Qt, | ||
// the licensors of this Program grant you additional permission to convey the resulting work. | ||
// See <https://developers.arcgis.com/qt/> for further information. | ||
|
||
#ifndef HEATRISKLISTMODEL_H | ||
#define HEATRISKLISTMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
#include <QObject> | ||
|
||
namespace Esri::ArcGISRuntime { | ||
class Feature; | ||
} // namespace Esri::ArcGISRuntime | ||
|
||
|
||
class HeatRiskAnalysisGroup | ||
{ | ||
public: | ||
HeatRiskAnalysisGroup(double heatRiskIndex); | ||
|
||
QString name() const; | ||
double heatRiskIndex() const; | ||
|
||
void addFeature(Esri::ArcGISRuntime::Feature *heatRiskFeature); | ||
|
||
private: | ||
double m_heatRiskIndex; | ||
QList<Esri::ArcGISRuntime::Feature*> m_heatRiskFeatures; | ||
}; | ||
|
||
|
||
class HeatRiskListModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
enum HeatRiskRoles { | ||
NameRole = Qt::UserRole + 1, | ||
RiskRole | ||
}; | ||
|
||
explicit HeatRiskListModel(QObject *parent = nullptr); | ||
|
||
void loadAnalysisGroups(const QList<HeatRiskAnalysisGroup> &analysisGroups); | ||
|
||
int rowCount(const QModelIndex & parent = QModelIndex()) const; | ||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; | ||
|
||
protected: | ||
QHash<int, QByteArray> roleNames() const; | ||
|
||
private: | ||
QList<HeatRiskAnalysisGroup> m_analysisGroups; | ||
}; | ||
|
||
#endif // HEATRISKLISTMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters