Skip to content
Browse files

Add a user-friendly settings dialog capable of storing the minimum su…

…pport, minimum PatternTree support and minimum confidence through QSettings.
  • Loading branch information...
1 parent c38f293 commit a74e1e063a701c4b0a99d180bacacdc86247cd8a @wimleers committed Jun 29, 2011
Showing with 222 additions and 3 deletions.
  1. +16 −1 code/UI/MainWindow.cpp
  2. +4 −0 code/UI/MainWindow.h
  3. +152 −0 code/UI/SettingsDialog.cpp
  4. +46 −0 code/UI/SettingsDialog.h
  5. +4 −2 code/UI/UI.pri
View
17 code/UI/MainWindow.cpp
@@ -336,6 +336,13 @@ void MainWindow::importFile() {
}
}
+void MainWindow::settingsDialog() {
+ SettingsDialog * settingsDialog = new SettingsDialog(this);
+ settingsDialog->show();
+ settingsDialog->raise();
+ settingsDialog->activateWindow();
+}
+
//------------------------------------------------------------------------------
// Private methods: logic.
@@ -358,7 +365,11 @@ void MainWindow::initLogic() {
// TODO: when these parameters have been figured out, they should be the defaults
// and therefor they should be moved to the Analyst constructor.
- this->analyst = new Analytics::Analyst(0.05, 0.04, 0.2);
+ QSettings settings;
+ double minSupport = settings.value("analyst/minimumSupport", 0.05).toDouble();
+ double minPatternTreeSupport = settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble();
+ double minConfidence = settings.value("analyst/minimumConfidence", 0.2).toDouble();
+ this->analyst = new Analytics::Analyst(minSupport, minPatternTreeSupport, minConfidence);
// Set constraints. This defines which associations will be found. By
// default, only causes for slow episodes will be searched.
@@ -733,6 +744,9 @@ void MainWindow::createMenuBar() {
this->menuFileImport->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
this->menuFile->addAction(this->menuFileImport);
+ this->menuFileSettings = new QAction(tr("Settings"), this->menuFile);
+ this->menuFile->addAction(this->menuFileSettings);
+
menuBar->addMenu(this->menuFile);
}
@@ -744,4 +758,5 @@ void MainWindow::connectUI() {
// Menus.
connect(this->menuFileImport, SIGNAL(triggered()), SLOT(importFile()));
+ connect(this->menuFileSettings, SIGNAL(triggered()), SLOT(settingsDialog()));
}
View
4 code/UI/MainWindow.h
@@ -28,6 +28,7 @@
#include <QLineEdit>
#include <QFileDialog>
#include <QDesktopServices>
+#include <QDialog>
#include <QTableView>
#include <QHeaderView>
@@ -40,6 +41,7 @@
#include "ConceptHierarchyCompleter.h"
#include "CausesTableFilterProxyModel.h"
+#include "SettingsDialog.h"
#include "../EpisodesParser/Parser.h"
#include "../Analytics/Analyst.h"
@@ -98,6 +100,7 @@ protected slots:
void causesFilterChanged(QString filterString);
void importFile();
+ void settingsDialog();
private:
// Logic.
@@ -181,6 +184,7 @@ protected slots:
// Menu bar.
QMenu * menuFile;
QAction * menuFileImport;
+ QAction * menuFileSettings;
};
#endif // MAINWINDOW_H
View
152 code/UI/SettingsDialog.cpp
@@ -0,0 +1,152 @@
+#include "SettingsDialog.h"
+
+SettingsDialog::SettingsDialog(QWidget * parent) :
+ QDialog(parent)
+{
+ QSettings settings;
+
+ QLabel * descriptionLabel = new QLabel(tr("Find causes for all problems that:"));
+
+ // Minimum frequent itemset support.
+ QHBoxLayout * minSupLayout = new QHBoxLayout();
+ QLabel * minSupPrefixLabel = new QLabel(tr("affect at least"));
+ QLabel * minSupSuffixLabel = new QLabel(tr("of all page views"));
+ this->minSupport = new QDoubleSpinBox();
+ this->minSupport->setSuffix("%");
+ this->minSupport->setMinimum(1);
+ this->minSupport->setMaximum(100);
+ this->minSupport->setValue(qRound(settings.value("analyst/minimumSupport", 0.05).toDouble() * 100));
+ minSupLayout->addWidget(minSupPrefixLabel);
+ minSupLayout->addWidget(this->minSupport);
+ minSupLayout->addWidget(minSupSuffixLabel);
+ minSupLayout->addStretch();
+
+ // Minimum PatternTree support.
+ QHBoxLayout * minPatternTreeSupLayout = new QHBoxLayout();
+ QLabel * minPatternTreeSupPrefixLabel = new QLabel(tr("(but allow a frequency estimation error margin of"));
+ QLabel * minPatternTreeSupSuffixLabel = new QLabel(tr(")"));
+ this->patternTreeSupportErrorMargin = new QDoubleSpinBox();
+ this->patternTreeSupportErrorMargin->setSuffix("%");
+ this->patternTreeSupportErrorMargin->setMinimum(1);
+ this->patternTreeSupportErrorMargin->setMaximum(100);
+ this->patternTreeSupportErrorMargin->setValue(SettingsDialog::absoluteToErrorMargin(this->minSupport->value(), settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble() * 100));
+
+ minPatternTreeSupLayout->addWidget(minPatternTreeSupPrefixLabel);
+ minPatternTreeSupLayout->addWidget(this->patternTreeSupportErrorMargin);
+ minPatternTreeSupLayout->addWidget(minPatternTreeSupSuffixLabel);
+ minPatternTreeSupLayout->addStretch();
+
+ // Minimum confidence.
+ QHBoxLayout * minConfidenceLayout = new QHBoxLayout();
+ QLabel * minConfidencePrefixLabel = new QLabel(tr("and are slow at least"));
+ QLabel * minConfidenceSuffixLabel = new QLabel(tr("of the time"));
+ this->minConfidence = new QDoubleSpinBox();
+ this->minConfidence->setSuffix("%");
+ this->minConfidence->setMinimum(1);
+ this->minConfidence->setMaximum(100);
+ this->minConfidence->setValue(qRound(settings.value("analyst/minimumConfidence", 0.2).toDouble() * 100));
+ minConfidenceLayout->addWidget(minConfidencePrefixLabel);
+ minConfidenceLayout->addWidget(this->minConfidence);
+ minConfidenceLayout->addWidget(minConfidenceSuffixLabel);
+ minConfidenceLayout->addStretch();
+
+ // Resulting parameters.
+ QGroupBox * resultingParameters = new QGroupBox(tr("Resulting parameters"));
+ QVBoxLayout * resultingParametersLayout = new QVBoxLayout();
+ resultingParameters->setLayout(resultingParametersLayout);
+
+ QHBoxLayout * rpMinSupportLayout = new QHBoxLayout();
+ this->resultingParametersMinSupport = new QLabel(QString("%1%").arg(QString::number(this->minSupport->value(), 'f', 2)));
+ rpMinSupportLayout->addWidget(new QLabel(tr("Minimum frequent itemset support") + ":"));
+ rpMinSupportLayout->addWidget(this->resultingParametersMinSupport);
+ rpMinSupportLayout->addStretch();
+ resultingParametersLayout->addLayout(rpMinSupportLayout);
+
+ QHBoxLayout * rpMinPatternTreeSupportLayout = new QHBoxLayout();
+ this->resultingParametersMinPatternTreeSupport = new QLabel(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()), 'f', 2)));
+ rpMinPatternTreeSupportLayout->addWidget(new QLabel(tr("Minimum PatternTree suppport") + ":"));
+ rpMinPatternTreeSupportLayout->addWidget(this->resultingParametersMinPatternTreeSupport);
+ rpMinPatternTreeSupportLayout->addStretch();
+ resultingParametersLayout->addLayout(rpMinPatternTreeSupportLayout);
+
+ QHBoxLayout * rpMinConfidenceLayout = new QHBoxLayout();
+ this->resultingParametersMinConfidence = new QLabel(QString("%1%").arg(QString::number(this->minConfidence->value(), 'f', 2)));
+ rpMinConfidenceLayout->addWidget(new QLabel(tr("Minimum confidence") + ":"));
+ rpMinConfidenceLayout->addWidget(this->resultingParametersMinConfidence);
+ rpMinConfidenceLayout->addStretch();
+ resultingParametersLayout->addLayout(rpMinConfidenceLayout);
+
+ // Buttons.
+ QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
+ buttonBox->addButton(QDialogButtonBox::Cancel);
+ buttonBox->addButton(QDialogButtonBox::Save);
+ buttonBox->button(QDialogButtonBox::RestoreDefaults)->setAutoDefault(false);
+
+ // Layout.
+ QVBoxLayout * mainLayout = new QVBoxLayout();
+ this->setLayout(mainLayout);
+ mainLayout->addWidget(descriptionLabel);
+ mainLayout->addLayout(minSupLayout);
+ mainLayout->addLayout(minPatternTreeSupLayout);
+ mainLayout->addLayout(minConfidenceLayout);
+ mainLayout->addWidget(resultingParameters);
+ mainLayout->addWidget(buttonBox);
+
+ connect(this->minSupport, SIGNAL(valueChanged(double)), SLOT(minSupportChanged(double)));
+ connect(this->minConfidence, SIGNAL(valueChanged(double)), SLOT(minConfidenceChanged(double)));
+ connect(this->patternTreeSupportErrorMargin, SIGNAL(valueChanged(double)), SLOT(patternTreeSupportErrorMarginChanged(double)));
+ connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(buttonRestoreDefaults()));
+ connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(buttonCancel()));
+ connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(buttonSave()));
+}
+
+double SettingsDialog::errorMarginToAbsolute(double minSupport, double errorMargin) {
+ double sigma = minSupport / 100.0;
+ double e = errorMargin / 100.0;
+ return sigma * (1 - e) * 100.0;
+}
+
+double SettingsDialog::absoluteToErrorMargin(double minSupport, double minPatternTreeSupport) {
+ double sigma = minSupport / 100.0;
+ double epsilon = minPatternTreeSupport / 100.0;
+ return (1.0 - (epsilon / sigma)) * 100.0;
+}
+
+void SettingsDialog::minSupportChanged(double value) {
+ this->resultingParametersMinSupport->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
+ this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(value, this->patternTreeSupportErrorMargin->value()), 'f', 2)));
+}
+
+void SettingsDialog::minConfidenceChanged(double value) {
+ this->resultingParametersMinConfidence->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
+}
+
+void SettingsDialog::patternTreeSupportErrorMarginChanged(double value) {
+ this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), value), 'f', 2)));
+}
+
+void SettingsDialog::buttonRestoreDefaults() {
+
+}
+
+void SettingsDialog::buttonCancel() {
+ this->close();
+}
+
+void SettingsDialog::buttonSave() {
+ QSettings settings;
+
+ settings.beginGroup("analyst");
+ settings.setValue("minimumSupport", this->minSupport->value() / 100.0);
+ qDebug() << "epsilon" << SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value());
+ settings.setValue("minimumPatternTreeSupport", SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()) / 100.0);
+ settings.setValue("minimumConfidence", this->minConfidence->value() / 100.0);
+ settings.endGroup();
+
+ settings.beginGroup("parser");
+ settings.endGroup();
+
+ this->close();
+}
View
46 code/UI/SettingsDialog.h
@@ -0,0 +1,46 @@
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QDoubleSpinBox>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QSettings>
+
+class SettingsDialog : public QDialog {
+
+ Q_OBJECT
+
+public:
+ explicit SettingsDialog(QWidget * parent = NULL);
+
+ static double errorMarginToAbsolute(double minSupport, double errorMargin);
+ static double absoluteToErrorMargin(double minSupport, double minPatternTreeSupport);
+
+signals:
+
+public slots:
+
+protected slots:
+ void minSupportChanged(double value);
+ void minConfidenceChanged(double value);
+ void patternTreeSupportErrorMarginChanged(double value);
+
+ void buttonRestoreDefaults();
+ void buttonCancel();
+ void buttonSave();
+
+protected:
+ QDoubleSpinBox * minSupport;
+ QDoubleSpinBox * minConfidence;
+ QDoubleSpinBox * patternTreeSupportErrorMargin;
+ QLabel * resultingParametersMinSupport;
+ QLabel * resultingParametersMinConfidence;
+ QLabel * resultingParametersMinPatternTreeSupport;
+};
+
+#endif // SETTINGSDIALOG_H
View
6 code/UI/UI.pri
@@ -5,11 +5,13 @@ INCLUDEPATH += $${PWD}
SOURCES += \
$${PWD}/MainWindow.cpp \
$${PWD}/ConceptHierarchyCompleter.cpp \
- $${PWD}/CausesTableFilterProxyModel.cpp
+ $${PWD}/CausesTableFilterProxyModel.cpp \
+ $${PWD}/SettingsDialog.cpp
HEADERS += \
$${PWD}/MainWindow.h \
$${PWD}/ConceptHierarchyCompleter.h \
- $${PWD}/CausesTableFilterProxyModel.h
+ $${PWD}/CausesTableFilterProxyModel.h \
+ $${PWD}/SettingsDialog.h
# Disable qDebug() output when in release mode.
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT

0 comments on commit a74e1e0

Please sign in to comment.
Something went wrong with that request. Please try again.