How to update C++ QAbstractListModel properly
-
Hello,
I'm currently working on refactoring/fixing some code. I have an issue I need help figuring out. I'm trying to figure out the best way to update the model/view once I get updated values from our backend application. The model handles Setting Objects. I have a client class that receives the parameter and its new value then goes to propagates that to a SettingsManager class. SettingsManager checks the new value coming in and saves it. Once that's saved what's the best way to update the model? Should I just create a signal to connect to SetData()?void SettingsManager::setValue(const QVariant& value, int setting) { SettingBase *SB = allSettingsMap.value(setting); if(SB != nullptr){ qDebug()<<" Updating setting: " << setting <<" in map to " << value; //allSettingsMap.value(setting)->setTempValue(value); // set temp value equal to value SB->setTempValue(value); SB->saveValue(); qDebug()<<" Setting Map Updated to " << value; emit settingValueChanged(setting, value); } }Would I just connect settingValueChanged to setData? And I'd need some function to calculate QModelIndex which gets tricky because I have multiple vectors of settings (One vector for each page of settings). Does anyone have a suggestion of how to update? To combat the current implementation has a bunch of signals emitting in the client and having qml connection types on the different qml pages. (See below)
if (paramName == QString("ampRating")) {settingmanager->setSettingValue(Settings::Parameter::AmpRating,value); emit updateTSModel(26,QVariant(value).toString(), 2);On that page then:
Connections { target: client onUpdateTSModel:{ console.log("SettingList.SetData()" + " index: " + m_idx + " value: " + m_value) mList.setData(mList.index(m_idx,0,mList), m_value, 259) } }