c++ - QTableView and unique IDs -


i'm new qt , coming c# .net. trying replicate simple program wrote in c# in qt learning tool. have data model inherits qabstracttablemodel , implements:

rowcount, columncount, data, setdata, headerdata flags

my data structure map

std::map<int, cbdatarow> 

so idea each row have unique int id , struct containing rest of row information.

what stuck on how update data model when user makes edit in qtableview object. setdata function called. here is:

bool cbdatabasemodel::setdata(const qmodelindex &index, const qvariant &value, int role) {     bool success = false;     if(role == qt::editrole) {         success = m_data.updaterow(index, value);     }      if(success) {         emit datachanged(index, index);         return true;     } else {         return false;     } } 

now see updaterow() function gets called here on edit. function should find unique id in map , update appropriate members of cbdatarow struct. problem have no idea how unique id out of qmodelindex object gets passed edit function.

for example: user edits "cb name" cell of row 3. data in row 3 has unique id of 100. value of 100 in qtableview in hidden column, column index 0. need simply: (psuedo code)

it = m_data.find(unique_id); it->second.cb_name = value.tostring(); 

since user editing column 1, how find unique id contained in column 0?

i recommend reimplement index() method of model , there create indexes using call createindex(row,col, unique_id);

then in place got qmodelindex, can extract unique_id = model_index.internalid();


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -