analyzer: fix suppression dialog

Task-number: QTCREATORBUG-6500
Change-Id: I8297c91238c4edfd28d9813a92f082f33a6e763a
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2011-12-16 16:06:25 +01:00
committed by hjk
parent bd308acfcf
commit 0594d64380
6 changed files with 91 additions and 189 deletions

View File

@@ -526,14 +526,7 @@ void MemcheckErrorView::contextMenuEvent(QContextMenuEvent *e)
void MemcheckErrorView::suppressError()
{
SuppressionDialog *dialog = new SuppressionDialog(this);
if (dialog->shouldShow()) {
dialog->setModal(true);
dialog->show();
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
} else {
delete dialog;
}
SuppressionDialog::maybeShow(this);
}
void MemcheckErrorView::goNext()

View File

@@ -37,9 +37,7 @@
#include <QtGui/QListView>
namespace Analyzer {
class AnalyzerSettings;
}
namespace Analyzer { class AnalyzerSettings; }
namespace Valgrind {
namespace Internal {
@@ -52,8 +50,8 @@ public:
MemcheckErrorView(QWidget *parent = 0);
~MemcheckErrorView();
// reimplemented to connect delegate to connection model after it has been set by
// superclass implementation
// Reimplemented to connect delegate to connection model after it has
// been set by superclass implementation.
void setModel(QAbstractItemModel *model);
void setDefaultSuppressionFile(const QString &suppFile);

View File

@@ -122,16 +122,34 @@ bool sortIndizesReverse(const QModelIndex &l, const QModelIndex &r)
return l.row() > r.row();
}
SuppressionDialog::SuppressionDialog(MemcheckErrorView *view)
: QDialog(),
m_view(view),
m_ui(new Ui::SuppressionDialog),
SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, const QList<Error> &errors)
: m_view(view),
m_settings(view->settings()),
m_cleanupIfCanceled(false)
m_cleanupIfCanceled(false),
m_errors(errors),
m_fileChooser(new Utils::PathChooser(this)),
m_suppressionEdit(new QPlainTextEdit(this))
{
m_ui->setupUi(this);
setWindowTitle(tr("Save Suppression"));
QLabel *fileLabel = new QLabel(tr("Suppression File:"), this);
QLabel *suppressionsLabel = new QLabel(tr("Suppression:"), this);
suppressionsLabel->setBuddy(m_suppressionEdit);
QFont font;
font.setFamily(QString::fromUtf8("Monospace"));
m_suppressionEdit->setFont(font);
m_buttonBox = new QDialogButtonBox(this);
m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save);
QFormLayout *formLayout = new QFormLayout(this);
formLayout->addRow(fileLabel, m_fileChooser);
formLayout->addRow(suppressionsLabel);
formLayout->addRow(m_suppressionEdit);
formLayout->addRow(m_buttonBox);
// NOTE: pathchooser requires existing files.
QFile defaultSuppFile(view->defaultSuppressionFile());
if (!defaultSuppFile.exists()) {
if (defaultSuppFile.open(QIODevice::WriteOnly)) {
@@ -140,60 +158,58 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view)
}
}
// NOTE: First set kind, then set path. Otherwise the file will be seen as "invalid".
m_ui->fileChooser->setExpectedKind(Utils::PathChooser::File);
m_ui->fileChooser->setPath(defaultSuppFile.fileName());
m_ui->fileChooser->setPromptDialogFilter(QLatin1String("*.supp"));
m_ui->fileChooser->setPromptDialogTitle(tr("Select Suppression File"));
connect(m_ui->fileChooser, SIGNAL(validChanged()),
SLOT(validate()));
connect(m_ui->suppressionEdit->document(), SIGNAL(contentsChanged()),
SLOT(validate()));
m_fileChooser->setExpectedKind(Utils::PathChooser::File);
m_fileChooser->setPath(defaultSuppFile.fileName());
m_fileChooser->setPromptDialogFilter(QLatin1String("*.supp"));
m_fileChooser->setPromptDialogTitle(tr("Select Suppression File"));
QString suppressions;
QModelIndexList indices = m_view->selectionModel()->selectedRows();
if (indices.isEmpty() && m_view->selectionModel()->currentIndex().isValid()) {
// can happen when using arrow keys to navigate and shortcut to trigger suppression
indices.append(m_view->selectionModel()->currentIndex());
}
foreach (const QModelIndex &index, indices) {
Error error = m_view->model()->data(index, ErrorListModel::ErrorRole).value<Error>();
if (!error.suppression().isNull())
m_errors.append(error);
}
foreach (const Error &error, m_errors)
suppressions += suppressionText(error);
m_ui->suppressionEdit->setPlainText(suppressions);
m_suppressionEdit->setPlainText(suppressions);
setWindowTitle(tr("Save Suppression"));
connect(m_fileChooser, SIGNAL(validChanged()), SLOT(validate()));
connect(m_suppressionEdit->document(), SIGNAL(contentsChanged()), SLOT(validate()));
connect(m_buttonBox, SIGNAL(accepted()), SLOT(accept()));
connect(m_buttonBox, SIGNAL(rejected()), SLOT(reject()));
}
SuppressionDialog::~SuppressionDialog()
void SuppressionDialog::maybeShow(MemcheckErrorView *view)
{
delete m_ui;
}
QModelIndexList indices = view->selectionModel()->selectedRows();
// Can happen when using arrow keys to navigate and shortcut to trigger suppression:
if (indices.isEmpty() && view->selectionModel()->currentIndex().isValid())
indices.append(view->selectionModel()->currentIndex());
bool SuppressionDialog::shouldShow() const
{
return !m_errors.isEmpty();
QList<XmlProtocol::Error> errors;
foreach (const QModelIndex &index, indices) {
Error error = view->model()->data(index, ErrorListModel::ErrorRole).value<Error>();
if (!error.suppression().isNull())
errors.append(error);
}
if (errors.isEmpty())
return;
SuppressionDialog dialog(view, errors);
dialog.exec();
}
void SuppressionDialog::accept()
{
const QString path = m_ui->fileChooser->path();
const QString path = m_fileChooser->path();
QTC_ASSERT(!path.isEmpty(), return);
QTC_ASSERT(!m_ui->suppressionEdit->toPlainText().trimmed().isEmpty(), return);
QTC_ASSERT(!m_suppressionEdit->toPlainText().trimmed().isEmpty(), return);
Utils::FileSaver saver(path, QIODevice::Append);
QTextStream stream(saver.file());
stream << m_ui->suppressionEdit->toPlainText();
stream << m_suppressionEdit->toPlainText();
saver.setResult(&stream);
if (!saver.finalize(this))
return;
// add file to project (if there is a project that contains this file on the file system)
// Add file to project if there is a project containing this file on the file system.
ProjectExplorer::SessionManager *session = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
if (!session->projectForFile(path)) {
foreach (ProjectExplorer::Project *p, session->projects()) {
@@ -208,30 +224,30 @@ void SuppressionDialog::accept()
QModelIndexList indices = m_view->selectionModel()->selectedRows();
qSort(indices.begin(), indices.end(), sortIndizesReverse);
QAbstractItemModel *model = m_view->model();
foreach (const QModelIndex &index, indices) {
bool removed = m_view->model()->removeRow(index.row());
bool removed = model->removeRow(index.row());
QTC_ASSERT(removed, qt_noop());
Q_UNUSED(removed);
}
// one suppression might hide multiple rows, care for that
for (int row = 0; row < m_view->model()->rowCount(); ++row ) {
const Error rowError = m_view->model()->data(
m_view->model()->index(row, 0), ErrorListModel::ErrorRole).value<Error>();
// One suppression might hide multiple rows, care for that.
for (int row = 0; row < model->rowCount(); ++row ) {
const Error rowError = model->data(
model->index(row, 0), ErrorListModel::ErrorRole).value<Error>();
foreach (const Error &error, m_errors) {
if (equalSuppression(rowError, error)) {
bool removed = m_view->model()->removeRow(row);
QTC_ASSERT(removed, qt_noop());
Q_UNUSED(removed);
// gets increased in the for loop again
bool removed = model->removeRow(row);
QTC_CHECK(removed);
// Gets incremented in the for loop again.
--row;
break;
}
}
}
// select a new item
// Select a new item.
m_view->setCurrentIndex(indices.first());
QDialog::accept();
@@ -247,10 +263,10 @@ void SuppressionDialog::reject()
void SuppressionDialog::validate()
{
bool valid = m_ui->fileChooser->isValid()
&& !m_ui->suppressionEdit->toPlainText().trimmed().isEmpty();
bool valid = m_fileChooser->isValid()
&& !m_suppressionEdit->toPlainText().trimmed().isEmpty();
m_ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
m_buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
}
} // namespace Internal

View File

@@ -37,19 +37,20 @@
#include "xmlprotocol/error.h"
#include <utils/pathchooser.h>
#include <QtGui/QDialog>
namespace Analyzer {
class AnalyzerSettings;
}
QT_BEGIN_NAMESPACE
class QPlainTextEdit;
class QDialogButtonBox;
QT_END_NAMESPACE
namespace Analyzer { class AnalyzerSettings; }
namespace Valgrind {
namespace Internal {
namespace Ui {
class SuppressionDialog;
}
class MemcheckErrorView;
class SuppressionDialog : public QDialog
@@ -57,23 +58,25 @@ class SuppressionDialog : public QDialog
Q_OBJECT
public:
SuppressionDialog(MemcheckErrorView *view);
~SuppressionDialog();
virtual void accept();
virtual void reject();
bool shouldShow() const;
SuppressionDialog(MemcheckErrorView *view,
const QList<XmlProtocol::Error> &errors);
static void maybeShow(MemcheckErrorView *view);
private slots:
void validate();
private:
void accept();
void reject();
MemcheckErrorView *m_view;
Ui::SuppressionDialog *m_ui;
Analyzer::AnalyzerSettings *m_settings;
bool m_cleanupIfCanceled;
QList<XmlProtocol::Error> m_errors;
Utils::PathChooser *m_fileChooser;
QPlainTextEdit *m_suppressionEdit;
QDialogButtonBox *m_buttonBox;
};
} // namespace Internal

View File

@@ -1,107 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Valgrind::Internal::SuppressionDialog</class>
<widget class="QDialog" name="Valgrind::Internal::SuppressionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>718</width>
<height>424</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="fileLabel">
<property name="text">
<string>Suppression File:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::PathChooser" name="fileChooser" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="suppressionsLabel">
<property name="text">
<string>Suppression:</string>
</property>
<property name="buddy">
<cstring>suppressionEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPlainTextEdit" name="suppressionEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Monospace</family>
</font>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Memcheck::Internal::SuppressionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>322</x>
<y>391</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Memcheck::Internal::SuppressionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>254</x>
<y>391</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -55,6 +55,5 @@ SOURCES += \
suppressiondialog.cpp
FORMS += \
valgrindconfigwidget.ui \
suppressiondialog.ui
valgrindconfigwidget.ui