| 159 | } |
| 160 | |
| 161 | QModelIndex QmitkPropertyItemModel::FindProperty(const mitk::BaseProperty *property) |
| 162 | { |
| 163 | if (property == nullptr) |
| 164 | return QModelIndex(); |
| 165 | |
| 166 | auto propertyList = m_PropertyList.Lock(); |
| 167 | |
| 168 | if (propertyList.IsNull()) |
| 169 | return QModelIndex(); |
| 170 | |
| 171 | auto propertyMap = propertyList->GetMap(); |
| 172 | auto it = std::find_if(propertyMap->begin(), propertyMap->end(), PropertyEqualTo(property)); |
| 173 | |
| 174 | if (it == propertyMap->end()) |
| 175 | return QModelIndex(); |
| 176 | |
| 177 | QString name = QString::fromStdString(it->first); |
| 178 | |
| 179 | if (!name.contains('.')) |
| 180 | { |
| 181 | QModelIndexList item = this->match(index(0, 0), Qt::DisplayRole, name, 1, Qt::MatchExactly); |
| 182 | |
| 183 | if (!item.empty()) |
| 184 | return item[0]; |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | QStringList names = name.split('.'); |
| 189 | QModelIndexList items = |
| 190 | this->match(index(0, 0), Qt::DisplayRole, names.last(), -1, Qt::MatchRecursive | Qt::MatchExactly); |
| 191 | |
| 192 | for (auto item : std::as_const(items)) |
| 193 | { |
| 194 | QModelIndex candidate = item; |
| 195 | |
| 196 | for (int i = names.length() - 1; i != 0; --i) |
| 197 | { |
| 198 | QModelIndex parent = item.parent(); |
| 199 | |
| 200 | if (parent.parent() == QModelIndex()) |
| 201 | { |
| 202 | if (parent.data() != names.first()) |
| 203 | break; |
| 204 | |
| 205 | return candidate; |
| 206 | } |
| 207 | |
| 208 | if (parent.data() != names[i - 1]) |
| 209 | break; |
| 210 | |
| 211 | item = parent; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return QModelIndex(); |
| 217 | } |
| 218 |
no test coverage detected