Skip to content

Commit b5dc8fb

Browse files
authored
fix: select all checkbox inconsistent (#76)
When no migrators is available, "selectAll" check box shouldn't be visible cause there's nothing to select. Just disable item is not friendly for user, add message to notify user that there is no migrator available.
1 parent 89bb1b8 commit b5dc8fb

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/migrator/app/taskpage.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@ class TaskModel : public QAbstractListModel {
8383
migrators_ = factory_->list(availableAddons);
8484
migratorStatesCache_.resize(migrators_.size());
8585
int idx = 0;
86-
availMigrators_ = 0;
86+
auto tmpAvailMigrators = 0;
8787
for (const auto &migrator : migrators_) {
8888
migratorStatesCache_[idx] = migrator->check();
8989
if (migratorStatesCache_[idx]) {
90-
availMigrators_++;
90+
tmpAvailMigrators++;
9191
}
9292
idx++;
9393
}
9494
selected_.clear();
95+
setAvailMigrators(tmpAvailMigrators);
9596
endResetModel();
9697
Q_EMIT selectedChanged();
9798
}
@@ -116,7 +117,7 @@ class TaskModel : public QAbstractListModel {
116117
}
117118

118119
bool allSelected() const {
119-
return static_cast<int>(availMigrators_) == selected_.size();
120+
return availMigrators_ != 0 && static_cast<int>(availMigrators_) == selected_.size();
120121
}
121122

122123
bool someSelected() const { return !selected_.isEmpty(); }
@@ -129,8 +130,16 @@ class TaskModel : public QAbstractListModel {
129130
return result;
130131
}
131132

133+
void setAvailMigrators(int availMigrators) {
134+
if (availMigrators == static_cast<int>(availMigrators_))
135+
return;
136+
availMigrators_ = availMigrators;
137+
Q_EMIT availMigratorsChanged(availMigrators_);
138+
}
139+
132140
Q_SIGNALS:
133141
void selectedChanged();
142+
void availMigratorsChanged(int);
134143

135144
private:
136145
const MigratorFactory *factory_;
@@ -148,7 +157,8 @@ TaskPage::TaskPage(MainWindow *parent)
148157
taskView->setModel(model_);
149158
fcitxNotRunningMessage->setVisible(!parent_->dbus()->available());
150159

151-
descriptionLabel->setText(_("Click on an item for more details."));
160+
selectAllBox->hide();
161+
descriptionLabel->setText(_("No available migrators."));
152162
connect(taskView->selectionModel(), &QItemSelectionModel::currentChanged,
153163
this, [this](const QModelIndex &current) {
154164
if (current.isValid()) {
@@ -163,6 +173,15 @@ TaskPage::TaskPage(MainWindow *parent)
163173
selectAllBox->setChecked(model_->allSelected());
164174
Q_EMIT completeChanged();
165175
});
176+
connect(model_, &TaskModel::availMigratorsChanged, this, [this](int availMigrators) {
177+
if (!availMigrators) {
178+
selectAllBox->hide();
179+
descriptionLabel->setText(_("No available migrators."));
180+
} else {
181+
selectAllBox->show();
182+
descriptionLabel->setText(_("Click on an item for more details."));
183+
}
184+
});
166185
connect(selectAllBox, &QCheckBox::clicked, this, [this](bool checked) {
167186
if (checked) {
168187
model_->selectAll();

0 commit comments

Comments
 (0)