<table><tr><td style="">sitter updated this revision to Diff 16865.<br />sitter retitled this revision from "do not keep constructing new selectionmodels" to "simplify setContents by letting Qt do more of the work".<br />sitter edited the summary of this revision. <a href="https://phabricator.kde.org/transactions/detail/PHID-XACT-DREV-aouldunmw2ph2yu/" rel="noreferrer">(Show Details)</a><br />sitter added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D6767" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>did some more digging with input from David.</p>
<p>we can do away with the selectionModel management entirely. QAIV manages the<br />
selectionModel itself via setModel.<br />
it also connects our input model's <tt style="background: #ebebeb; font-size: 13px;">destroyed()</tt> signal to the selection<br />
models deleteLater, so deleting our model will consistently clean up<br />
the selection as well.</p>
<p>additionally the mode and behavior setting affect only the view itself and<br />
are persistent across model changes, so we can move this to the ctor (where<br />
interstingly behavior was already set)</p>
<p>there's one more change we could do to this:<br />
right now we manually connect _k_slotSelectionChanged to the selection model,<br />
we need to do this every time we change model. alternatively we could also<br />
override the <tt style="background: #ebebeb; font-size: 13px;">protected virtual selectionChanged</tt>.<br />
except IIRC this would be BIC with MSVC so we probably don't want this</p></div></div><br /><div><strong>CHANGES TO REVISION SUMMARY</strong><div><div style="white-space: pre-wrap; color: #74777D;"><span style="padding: 0 2px; color: #333333; background: rgba(251, 175, 175, .7);">simply change its underlying model after it has been initialized once.</span><span style="padding: 0 2px; color: #333333; background: rgba(151, 234, 151, .6);">This is refactoring the code, it is doing the same as before.<br />
<br />
QTableView already manages its own selectionModel based on the model<br />
we give it there does not seem to be a reason why we would duplicate thise code<br />
<br />
- simplify the code managing the models by removing the manual selectionModel<br />
management and instead letting Qt handle its creation via QTableView::setModel<br />
- update the deletion comment to point out that deleting the old model will in<br />
fact also delete the associated automatically created selectionModel<br />
- move behavior and mode setup of the view to the constructor. a search<br />
on the QAbstractItemView suggests that neither setting is passed along<br />
nor mutated outside the setter, so we only need to set these up once</span><br />
<br />
ideally I suppose instead of changing the model at all we should have a<div style="padding: 8px 0;">...</div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R236 KWidgetsAddons</div></div></div><br /><div><strong>CHANGES SINCE LAST UPDATE</strong><div><a href="https://phabricator.kde.org/D6767?vs=16861&id=16865" rel="noreferrer">https://phabricator.kde.org/D6767?vs=16861&id=16865</a></div></div><br /><div><strong>BRANCH</strong><div><div>master</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D6767" rel="noreferrer">https://phabricator.kde.org/D6767</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>src/kcharselect.cpp</div></div></div><br /><div><strong>To: </strong>sitter, cfeck, davidedmundson<br /><strong>Cc: </strong>davidedmundson, Frameworks<br /></div>