diff --git a/src/libs/utils/submiteditorwidget.cpp b/src/libs/utils/submiteditorwidget.cpp index 233c5b5e153d2137e7935fccbb325a2fabc254c2..0742fc6a46f4da155aae12464283f617ae3ef0b0 100644 --- a/src/libs/utils/submiteditorwidget.cpp +++ b/src/libs/utils/submiteditorwidget.cpp @@ -176,6 +176,7 @@ struct SubmitEditorWidgetPrivate int m_lineWidth; bool m_commitEnabled; + bool m_ignoreChange; }; SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() : @@ -185,7 +186,8 @@ SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() : m_emptyFileListEnabled(false), m_fieldLayout(0), m_lineWidth(defaultLineWidth), - m_commitEnabled(false) + m_commitEnabled(false), + m_ignoreChange(false) { } @@ -211,6 +213,9 @@ SubmitEditorWidget::SubmitEditorWidget(QWidget *parent) : connect(m_d->m_ui.fileView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(diffActivated(QModelIndex))); + connect(m_d->m_ui.checkAllCheckBox, SIGNAL(stateChanged(int)), + this, SLOT(checkAllToggled())); + setFocusPolicy(Qt::StrongFocus); setFocusProxy(m_d->m_ui.description); } @@ -402,6 +407,10 @@ void SubmitEditorWidget::setFileModel(QAbstractItemModel *model) this, SLOT(updateSubmitAction())); connect(model, SIGNAL(modelReset()), this, SLOT(updateSubmitAction())); + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + this, SLOT(updateCheckAllComboBox())); + connect(model, SIGNAL(modelReset()), + this, SLOT(updateCheckAllComboBox())); connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateSubmitAction())); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), @@ -473,6 +482,7 @@ void SubmitEditorWidget::updateActions() { updateSubmitAction(); updateDiffAction(); + updateCheckAllComboBox(); } // Enable submit depending on having checked files @@ -505,6 +515,19 @@ void SubmitEditorWidget::updateDiffAction() } } +void SubmitEditorWidget::updateCheckAllComboBox() +{ + m_d->m_ignoreChange = true; + unsigned checkedCount = checkedFilesCount(); + if (checkedCount == 0) + m_d->m_ui.checkAllCheckBox->setCheckState(Qt::Unchecked); + else if (checkedCount == m_d->m_ui.fileView->model()->rowCount()) + m_d->m_ui.checkAllCheckBox->setCheckState(Qt::Checked); + else + m_d->m_ui.checkAllCheckBox->setCheckState(Qt::PartiallyChecked); + m_d->m_ignoreChange = false; +} + bool SubmitEditorWidget::hasSelection() const { // Not present until model is set @@ -600,6 +623,20 @@ void SubmitEditorWidget::editorCustomContextMenuRequested(const QPoint &pos) menu->exec(m_d->m_ui.description->mapToGlobal(pos)); } +void SubmitEditorWidget::checkAllToggled() +{ + if (m_d->m_ignoreChange) + return; + if (m_d->m_ui.checkAllCheckBox->checkState() == Qt::Checked + || m_d->m_ui.checkAllCheckBox->checkState() == Qt::PartiallyChecked) { + setListModelChecked(m_d->m_ui.fileView->model(), true, checkableColumn); + } else { + setListModelChecked(m_d->m_ui.fileView->model(), false, checkableColumn); + } + // Reset that again, so that the user can't do it + m_d->m_ui.checkAllCheckBox->setTristate(false); +} + void SubmitEditorWidget::checkAll() { setListModelChecked(m_d->m_ui.fileView->model(), true, checkableColumn); diff --git a/src/libs/utils/submiteditorwidget.h b/src/libs/utils/submiteditorwidget.h index 091cb46ac71702af9d7bf96713a6b72a327b41ce..69fc63d8c24dad3fb2ca408ebfe2b3e54bde413b 100644 --- a/src/libs/utils/submiteditorwidget.h +++ b/src/libs/utils/submiteditorwidget.h @@ -120,7 +120,9 @@ signals: void submitActionTextChanged(const QString &); void submitActionEnabledChanged(const bool); -public slots: +private slots: + void updateCheckAllComboBox(); + void checkAllToggled(); void checkAll(); void uncheckAll(); diff --git a/src/libs/utils/submiteditorwidget.ui b/src/libs/utils/submiteditorwidget.ui index 957210e40a5f7199ba1bd69bd4551479f7e38ff9..6d96ec00fbe79acd51ad8e0a3d6cd5ca9c76db10 100644 --- a/src/libs/utils/submiteditorwidget.ui +++ b/src/libs/utils/submiteditorwidget.ui @@ -42,6 +42,16 @@ <bool>true</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="checkAllCheckBox"> + <property name="text"> + <string>Check &all</string> + </property> + <property name="tristate"> + <bool>false</bool> + </property> + </widget> + </item> <item> <widget class="QTreeView" name="fileView"/> </item>