Changeset View
Changeset View
Standalone View
Standalone View
src/kpluginselector.cpp
Show First 20 Lines • Show All 277 Lines • ▼ Show 20 Line(s) | 255 | { | |||
---|---|---|---|---|---|
278 | 278 | | |||
279 | d->listView->setMouseTracking(true); | 279 | d->listView->setMouseTracking(true); | ||
280 | d->listView->viewport()->setAttribute(Qt::WA_Hover); | 280 | d->listView->viewport()->setAttribute(Qt::WA_Hover); | ||
281 | 281 | | |||
282 | connect(d->lineEdit, &QLineEdit::textChanged, d->proxyModel, &QSortFilterProxyModel::invalidate); | 282 | connect(d->lineEdit, &QLineEdit::textChanged, d->proxyModel, &QSortFilterProxyModel::invalidate); | ||
283 | connect(pluginDelegate, &Private::PluginDelegate::changed, this, &KPluginSelector::changed); | 283 | connect(pluginDelegate, &Private::PluginDelegate::changed, this, &KPluginSelector::changed); | ||
284 | connect(pluginDelegate, &Private::PluginDelegate::configCommitted, this, &KPluginSelector::configCommitted); | 284 | connect(pluginDelegate, &Private::PluginDelegate::configCommitted, this, &KPluginSelector::configCommitted); | ||
285 | 285 | | |||
286 | connect(this, &KPluginSelector::changed, [this]{ emit defaulted(isDefault()); }); | ||||
ervin: We generally don't "this->", also you're capturing too much with =, capturing this would be… | |||||
287 | | ||||
286 | layout->addWidget(d->lineEdit); | 288 | layout->addWidget(d->lineEdit); | ||
287 | layout->addWidget(d->listView); | 289 | layout->addWidget(d->listView); | ||
288 | layout->addWidget(d->dependenciesWidget); | 290 | layout->addWidget(d->dependenciesWidget); | ||
289 | 291 | | |||
290 | // When a KPluginSelector instance gets focus, | 292 | // When a KPluginSelector instance gets focus, | ||
291 | // it should pass over the focus to its child searchbar. | 293 | // it should pass over the focus to its child searchbar. | ||
292 | setFocusProxy(d->lineEdit); | 294 | setFocusProxy(d->lineEdit); | ||
293 | } | 295 | } | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 367 | for (int i = 0; i < d->pluginModel->rowCount(); i++) { | |||
370 | pluginEntry->cfgGroup.sync(); | 372 | pluginEntry->cfgGroup.sync(); | ||
371 | } | 373 | } | ||
372 | 374 | | |||
373 | emit changed(false); | 375 | emit changed(false); | ||
374 | } | 376 | } | ||
375 | 377 | | |||
376 | void KPluginSelector::defaults() | 378 | void KPluginSelector::defaults() | ||
377 | { | 379 | { | ||
380 | bool isChanged = false; | ||||
378 | for (int i = 0; i < d->pluginModel->rowCount(); i++) { | 381 | for (int i = 0; i < d->pluginModel->rowCount(); i++) { | ||
379 | const QModelIndex index = d->pluginModel->index(i, 0); | 382 | const QModelIndex index = d->pluginModel->index(i, 0); | ||
380 | PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer()); | 383 | PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer()); | ||
384 | isChanged |= pluginEntry->pluginInfo.isPluginEnabled() != pluginEntry->pluginInfo.isPluginEnabledByDefault(); | ||||
381 | d->pluginModel->setData(index, pluginEntry->pluginInfo.isPluginEnabledByDefault(), Qt::CheckStateRole); | 385 | d->pluginModel->setData(index, pluginEntry->pluginInfo.isPluginEnabledByDefault(), Qt::CheckStateRole); | ||
382 | } | 386 | } | ||
383 | 387 | | |||
384 | emit changed(true); | 388 | emit changed(isChanged); | ||
ervin: No need for the extra blank line | |||||
385 | } | 389 | } | ||
This logic looks wrong to me. isChanged indicates if an entry state was changed during the course of the call to defaults(). It's very possible it's false when getting out of the loop. I think in such a case we'd loose the information of being in a "dirty" state while defaults() wouldn't have changed state at all. ervin: This logic looks wrong to me.
isChanged indicates if an entry state was changed during the… | |||||
isPluginEnabled represent the current state (i.e. after load) so we compare the file value with default value bport: isPluginEnabled represent the current state (i.e. after load) so we compare the file value with… | |||||
I thought that was the current GUI state not the current storage state and got confused. I stand corrected. ervin: I thought that was the current GUI state not the current storage state and got confused. I… | |||||
386 | 390 | | |||
387 | bool KPluginSelector::isDefault() const | 391 | bool KPluginSelector::isDefault() const | ||
388 | { | 392 | { | ||
389 | for (int i = 0; i < d->pluginModel->rowCount(); i++) { | 393 | for (int i = 0; i < d->pluginModel->rowCount(); i++) { | ||
390 | const QModelIndex index = d->pluginModel->index(i, 0); | 394 | const QModelIndex index = d->pluginModel->index(i, 0); | ||
391 | PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer()); | 395 | PluginEntry *pluginEntry = static_cast<PluginEntry *>(index.internalPointer()); | ||
392 | if (d->pluginModel->data(index, Qt::CheckStateRole).toBool() != pluginEntry->pluginInfo.isPluginEnabledByDefault()) { | 396 | if (d->pluginModel->data(index, Qt::CheckStateRole).toBool() != pluginEntry->pluginInfo.isPluginEnabledByDefault()) { | ||
393 | return false; | 397 | return false; | ||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Line(s) | 778 | { | |||
781 | pluginSelector_d->dependenciesWidget->clearDependencies(); | 785 | pluginSelector_d->dependenciesWidget->clearDependencies(); | ||
782 | 786 | | |||
783 | PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value<PluginEntry *>(); | 787 | PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value<PluginEntry *>(); | ||
784 | pluginSelector_d->updateDependencies(pluginEntry, state); | 788 | pluginSelector_d->updateDependencies(pluginEntry, state); | ||
785 | 789 | | |||
786 | const_cast<QAbstractItemModel *>(index.model())->setData(index, state, Qt::CheckStateRole); | 790 | const_cast<QAbstractItemModel *>(index.model())->setData(index, state, Qt::CheckStateRole); | ||
787 | } | 791 | } | ||
788 | 792 | | |||
789 | void KPluginSelector::Private::PluginDelegate::emitChanged() | 793 | void KPluginSelector::Private::PluginDelegate::emitChanged(bool state) | ||
790 | { | 794 | { | ||
791 | emit changed(true); | 795 | const QModelIndex index = focusedIndex(); | ||
796 | PluginEntry *pluginEntry = index.model()->data(index, PluginEntryRole).value<PluginEntry *>(); | ||||
797 | | ||||
798 | emit changed(pluginEntry->pluginInfo.isPluginEnabled() != state); | ||||
792 | } | 799 | } | ||
793 | 800 | | |||
794 | void KPluginSelector::Private::PluginDelegate::slotAboutClicked() | 801 | void KPluginSelector::Private::PluginDelegate::slotAboutClicked() | ||
795 | { | 802 | { | ||
796 | const QModelIndex index = focusedIndex(); | 803 | const QModelIndex index = focusedIndex(); | ||
797 | const QAbstractItemModel *model = index.model(); | 804 | const QAbstractItemModel *model = index.model(); | ||
798 | 805 | | |||
799 | PluginEntry *pluginEntry = model->data(index, PluginEntryRole).value<PluginEntry *>(); | 806 | PluginEntry *pluginEntry = model->data(index, PluginEntryRole).value<PluginEntry *>(); | ||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |
We generally don't "this->", also you're capturing too much with =, capturing this would be enough.