MCPcopy Create free account
hub / github.com/commontk/CTK / updateCheckState

Method updateCheckState

Libs/Widgets/ctkCheckableModelHelper.cpp:161–217  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

159
160//-----------------------------------------------------------------------------
161void ctkCheckableModelHelperPrivate
162::updateCheckState(const QModelIndex& modelIndex)
163{
164 Q_Q(ctkCheckableModelHelper);
165 bool checkable = false;
166 int oldCheckState = this->checkState(modelIndex, &checkable);
167 if (!checkable)
168 {
169 return;
170 }
171
172 Qt::CheckState newCheckState = Qt::PartiallyChecked;
173 bool firstCheckableChild = true;
174 const int rowCount = q->orientation() == Qt::Horizontal ?
175 q->model()->rowCount(modelIndex) : 1;
176 const int columnCount = q->orientation() == Qt::Vertical ?
177 q->model()->columnCount(modelIndex) : 1;
178 for (int r = 0; r < rowCount; ++r)
179 {
180 for (int c = 0; c < columnCount; ++c)
181 {
182 QModelIndex child = q->model()->index(r, c, modelIndex);
183 QVariant childCheckState = q->model()->data(child, Qt::CheckStateRole);
184 int childState = childCheckState.toInt(&checkable);
185 if (!checkable)
186 {
187 continue;
188 }
189 if (firstCheckableChild)
190 {
191 newCheckState = static_cast<Qt::CheckState>(childState);
192 firstCheckableChild = false;
193 }
194 if (newCheckState != childState)
195 {
196 newCheckState = Qt::PartiallyChecked;
197 }
198 if (newCheckState == Qt::PartiallyChecked)
199 {
200 break;
201 }
202 }
203 if (!firstCheckableChild && newCheckState == Qt::PartiallyChecked)
204 {
205 break;
206 }
207 }
208 if (oldCheckState == newCheckState)
209 {
210 return;
211 }
212 this->setCheckState(modelIndex, newCheckState);
213 if (modelIndex != q->rootIndex())
214 {
215 this->updateCheckState(modelIndex.parent());
216 }
217}
218

Callers 2

onDataChangedMethod · 0.80

Calls 11

rootIndexMethod · 0.80
checkStateMethod · 0.45
orientationMethod · 0.45
rowCountMethod · 0.45
modelMethod · 0.45
columnCountMethod · 0.45
indexMethod · 0.45
dataMethod · 0.45
toIntMethod · 0.45
setCheckStateMethod · 0.45
parentMethod · 0.45

Tested by

no test coverage detected