Commit f73895a6 authored by dt's avatar dt

Submit Editor: Add check all checkbox

Task-Nr: QTCREATORBUG-3539
parent 46945a62
......@@ -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);
......
......@@ -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();
......
......@@ -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 &amp;all</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="fileView"/>
</item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment