knro
27th September 2015, 22:30
My data is arranged like this:
City1
+ Long1, Lat1
+ Long2, Lat2
City2
+ Long1, Lat1
+ Long2, Lat2
+ Long3, Lat3
So basically each city has a list of longitudes/latitudes associated with it. I want to display the Cities in a QListView and only the coordinates in a QTableView and have the table view contents gets updated when the user selects a different city. I'm not sure how to exactly approach this. Do I create a model with 3 columns (city, long, lat)? Do I create two models? What I did is that I created one model CityModel based on QStandardItemModel and then for each city I created QStandardItem and then used CityModel.appendRow(cityItem). Then I created two QStandardItem for Longitude/Latitude and added them to cityItem.appendRow(..), and the two views use the same model, but only the QListView displays the data, while the QTableView is empty (probably because the coordinates items are children of the city item).
I'm not sure how to proceed with this as I'm new to the model/view architecture and it's a bit confusing.
City1
+ Long1, Lat1
+ Long2, Lat2
City2
+ Long1, Lat1
+ Long2, Lat2
+ Long3, Lat3
So basically each city has a list of longitudes/latitudes associated with it. I want to display the Cities in a QListView and only the coordinates in a QTableView and have the table view contents gets updated when the user selects a different city. I'm not sure how to exactly approach this. Do I create a model with 3 columns (city, long, lat)? Do I create two models? What I did is that I created one model CityModel based on QStandardItemModel and then for each city I created QStandardItem and then used CityModel.appendRow(cityItem). Then I created two QStandardItem for Longitude/Latitude and added them to cityItem.appendRow(..), and the two views use the same model, but only the QListView displays the data, while the QTableView is empty (probably because the coordinates items are children of the city item).
I'm not sure how to proceed with this as I'm new to the model/view architecture and it's a bit confusing.