Replace color description if different (usually coming from loading)

This commit is contained in:
Julien Wadel 2021-11-01 17:12:58 +01:00
parent 52a65d28ad
commit 2feff509ae
2 changed files with 16 additions and 9 deletions

View file

@ -114,8 +114,20 @@ void ColorListModel::add(std::shared_ptr<ColorModel> color){
emit layoutChanged();
}
QString ColorListModel::buildDescription(QString description){
QStringList tokens = description.split('_');
for(int index = 0 ; index < tokens.size() ; ++index)
if(mKeywordsMap.contains(tokens[index]))
tokens[index] = mKeywordsMap[tokens[index]];
description = tokens.join(' ');
description[0] = description[0].toUpper();
return description;
}
ColorModel * ColorListModel::add(const QString& id, const QString& idLink, QString description, QString colorValue){
ColorModel * color = getColor(id);
if( description == "")
description = buildDescription(id);
if(!color){
if(idLink != ""){
if( colorValue == ""){
@ -126,19 +138,13 @@ ColorModel * ColorListModel::add(const QString& id, const QString& idLink, QStri
}
addLink(id, idLink);
}
if( description == ""){
description = id;
QStringList tokens = description.split('_');
for(int index = 0 ; index < tokens.size() ; ++index)
if(mKeywordsMap.contains(tokens[index]))
tokens[index] = mKeywordsMap[tokens[index]];
description = tokens.join(' ');
description[0] = description[0].toUpper();
}
auto colorShared = std::make_shared<ColorModel>(id, colorValue, description);
add(colorShared);
color = colorShared.get();
emit colorChanged();
}else if( description != color->getDescription()) {
color->setDescription(description);
emit colorChanged();
}
return color;
}

View file

@ -333,6 +333,7 @@ private:
void add(std::shared_ptr<ColorModel> imdn);
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
virtual bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
QString buildDescription(QString description); // return a description from id by splitting '_'
QList<std::shared_ptr<ColorModel>> mList;