diff --git a/src/backend/hypothesisTest/HypothesisTest.h b/src/backend/hypothesisTest/HypothesisTest.h --- a/src/backend/hypothesisTest/HypothesisTest.h +++ b/src/backend/hypothesisTest/HypothesisTest.h @@ -82,6 +82,7 @@ void setSignificanceLevel(QVariant alpha); QString testName(); QString statsTable(); + QMap* tooltips(); void performTest(Test m_test, bool categoricalVariable = true, bool equalVariance = true); // void performTwoSampleIndependentTTest(bool categorical_variable, bool equal_variance); diff --git a/src/backend/hypothesisTest/HypothesisTest.cpp b/src/backend/hypothesisTest/HypothesisTest.cpp --- a/src/backend/hypothesisTest/HypothesisTest.cpp +++ b/src/backend/hypothesisTest/HypothesisTest.cpp @@ -99,7 +99,11 @@ } QString HypothesisTest::statsTable() { - return d->statsTable; + return d->statsTable; +} + +QMap* HypothesisTest::tooltips() { + return d->tooltips; } void HypothesisTest::performTest(Test test, bool categoricalVariable, bool equalVariance) { @@ -107,6 +111,7 @@ d->pValue.clear(); d->statisticValue.clear(); d->statsTable = ""; + d->tooltips->clear(); for (int i = 0; i < 10; i++) d->resultLine[i]->clear(); @@ -167,7 +172,8 @@ //TODO: add tooltip to tables. (currently it is not possible to use with QTextDocument); HypothesisTestPrivate::HypothesisTestPrivate(HypothesisTest* owner) : q(owner), - summaryLayout(new QVBoxLayout()) { + summaryLayout(new QVBoxLayout()), + tooltips(new QMap){ for (int i = 0; i < 10; i++) { resultLine[i] = new QLabel(); @@ -788,10 +794,10 @@ // printing table; // cell constructor structure; data, level, rowSpanCount, columnSpanCount, isHeader; QList rowMajor; - rowMajor.append(new Cell("", 0, true, 2, 1)); + rowMajor.append(new Cell("", 0, true, "", 2, 1)); for (int i = 0; i < np_b; i++) - rowMajor.append(new Cell(partitionNames_b[i], 0, true, 1, 2)); - rowMajor.append(new Cell("Mean", 0, true, 2)); + rowMajor.append(new Cell(partitionNames_b[i], 0, true, "", 1, 2)); + rowMajor.append(new Cell("Mean", 0, true, "", 2)); for (int i = 0; i < np_b; i++) { rowMajor.append(new Cell("Mean", 1, true)); @@ -811,7 +817,7 @@ rowMajor.append(new Cell("Mean", level, true)); for (int i = 0; i < np_b; i++) - rowMajor.append(new Cell(round(mean_b[i]), level, false, 1, 2)); + rowMajor.append(new Cell(round(mean_b[i]), level, false, "", 1, 2)); rowMajor.append(new Cell(round(mean), level)); statsTable = "

" + i18n("Contingency Table") + "

"; @@ -824,7 +830,7 @@ level = 0; rowMajor.append(new Cell("", level, true)); rowMajor.append(new Cell("SS", level, true)); - rowMajor.append(new Cell("DF", level, true)); + rowMajor.append(new Cell("DF", level, true, "degree of freedom")); rowMajor.append(new Cell("MS", level, true)); level++; @@ -1528,6 +1534,7 @@ } QString HypothesisTestPrivate::getHtmlTable3(const QList& rowMajor) { + tooltips->clear(); int rowMajorSize = rowMajor.size(); if (rowMajorSize == 0) @@ -1566,6 +1573,9 @@ ">" + i18n("%1", currCell->data) + cellEndTag; + + if (!currCell->tooltip.isEmpty()) + tooltips->insert(currCell->data, currCell->tooltip); } table += " "; table += ""; diff --git a/src/backend/hypothesisTest/HypothesisTestPrivate.h b/src/backend/hypothesisTest/HypothesisTestPrivate.h --- a/src/backend/hypothesisTest/HypothesisTestPrivate.h +++ b/src/backend/hypothesisTest/HypothesisTestPrivate.h @@ -1,9 +1,9 @@ /*************************************************************************** - File : HypothesisTestPrivate.h - Project : LabPlot - Description : Private members of Hypothesis Test - -------------------------------------------------------------------- - Copyright : (C) 2019 Devanshu Agarwal(agarwaldevanshu8@gmail.com) + File : HypothesisTestPrivate.h + Project : LabPlot + Description : Private members of Hypothesis Test + -------------------------------------------------------------------- + Copyright : (C) 2019 Devanshu Agarwal(agarwaldevanshu8@gmail.com) ***************************************************************************/ @@ -35,8 +35,8 @@ class HypothesisTestPrivate { public: - explicit HypothesisTestPrivate(HypothesisTest*); - virtual ~HypothesisTestPrivate(); + explicit HypothesisTestPrivate(HypothesisTest*); + virtual ~HypothesisTestPrivate(); struct Node { QString data; @@ -52,61 +52,64 @@ struct Cell { QString data; int level; + bool isHeader; + QString tooltip; int rowSpanCount; int columnSpanCount; - bool isHeader; - Cell(QVariant data = "", int level = 0, bool isHeader = false, int rowSpanCount = 1, int columnSpanCount = 1) { + Cell(QVariant data = "", int level = 0, bool isHeader = false, QString tooltip = "", int rowSpanCount = 1, int columnSpanCount = 1) { this->data = data.toString(); this->level = level; this->isHeader = isHeader; + this->tooltip = tooltip; this->rowSpanCount = rowSpanCount; this->columnSpanCount = columnSpanCount; } }; - enum ErrorType {ErrorUnqualSize, ErrorEmptyColumn, NoError}; + enum ErrorType {ErrorUnqualSize, ErrorEmptyColumn, NoError}; - QString name() const; - void setDataSourceSpreadsheet(Spreadsheet* spreadsheet); - void setColumns(QStringList cols); - void performTwoSampleIndependentTest(HypothesisTest::Test::Type test, bool categoricalVariable = false, bool equalVariance = true); - void performTwoSamplePairedTest(HypothesisTest::Test::Type test); - void performOneSampleTest(HypothesisTest::Test::Type test); - void performOneWayAnova(); + QString name() const; + void setDataSourceSpreadsheet(Spreadsheet* spreadsheet); + void setColumns(QStringList cols); + void performTwoSampleIndependentTest(HypothesisTest::Test::Type test, bool categoricalVariable = false, bool equalVariance = true); + void performTwoSamplePairedTest(HypothesisTest::Test::Type test); + void performOneSampleTest(HypothesisTest::Test::Type test); + void performOneWayAnova(); void performTwoWayAnova(); - void performLeveneTest(bool categoricalVariable); + void performLeveneTest(bool categoricalVariable); - HypothesisTest* const q; - HypothesisTest::DataSourceType dataSourceType{HypothesisTest::DataSourceSpreadsheet}; - Spreadsheet* dataSourceSpreadsheet{nullptr}; - QVector columns; - QStringList allColumns; + HypothesisTest* const q; + HypothesisTest::DataSourceType dataSourceType{HypothesisTest::DataSourceSpreadsheet}; + Spreadsheet* dataSourceSpreadsheet{nullptr}; + QVector columns; + QStringList allColumns; // int rowCount{0}; // int columnCount{0}; - QString currTestName{"Result Table"}; - double populationMean; - double significanceLevel; - QString statsTable; - HypothesisTest::Test::Tail tailType; + QString currTestName{"Result Table"}; + double populationMean; + double significanceLevel; + QString statsTable; + HypothesisTest::Test::Tail tailType; QList pValue; QList statisticValue; - QVBoxLayout* summaryLayout{nullptr}; - QLabel* resultLine[10]; + QVBoxLayout* summaryLayout{nullptr}; + QLabel* resultLine[10]; + QMap* tooltips; private: - bool isNumericOrInteger(Column* column); + bool isNumericOrInteger(Column* column); QString round(QVariant number, int precision = 3); void countPartitions(Column* column, int& np, int& totalRows); - ErrorType findStats(const Column* column,int& count, double& sum, double& mean, double& std); - ErrorType findStatsPaired(const Column* column1, const Column* column2, int& count, double& sum, double& mean, double& std); - ErrorType findStatsCategorical(Column* column1, Column* column2, int n[], double sum[], double mean[], double std[], QMap& colName, const int& np, const int& totalRows); + ErrorType findStats(const Column* column,int& count, double& sum, double& mean, double& std); + ErrorType findStatsPaired(const Column* column1, const Column* column2, int& count, double& sum, double& mean, double& std); + ErrorType findStatsCategorical(Column* column1, Column* column2, int n[], double sum[], double mean[], double std[], QMap& colName, const int& np, const int& totalRows); - double getPValue(const HypothesisTest::Test::Type& test, double& value, const QString& col1Name, const QString& col2name, const double mean, const double sp, const int df); + double getPValue(const HypothesisTest::Test::Type& test, double& value, const QString& col1Name, const QString& col2name, const double mean, const double sp, const int df); int setSpanValues(Node* root, int& totalLevels); QString getHtmlHeader(Node* root); QString getHtmlTable2(int rowCount, int columnCount, Node* columnHeaderRoot, QVariant* rowMajor); @@ -114,12 +117,12 @@ QString getHtmlTable3(const QList& rowMajor); - QString getLine(const QString& msg, const QString& color = "black"); - void printLine(const int& index, const QString& msg, const QString& color = "black"); - void printTooltip(const int& index, const QString& msg); - void printError(const QString& errorMsg); + QString getLine(const QString& msg, const QString& color = "black"); + void printLine(const int& index, const QString& msg, const QString& color = "black"); + void printTooltip(const int& index, const QString& msg); + void printError(const QString& errorMsg); - bool m_dbCreated{false}; + bool m_dbCreated{false}; }; #endif diff --git a/src/kdefrontend/hypothesisTest/HypothesisTestView.h b/src/kdefrontend/hypothesisTest/HypothesisTestView.h --- a/src/kdefrontend/hypothesisTest/HypothesisTestView.h +++ b/src/kdefrontend/hypothesisTest/HypothesisTestView.h @@ -49,6 +49,7 @@ class QItemSelection; class QLabel; class QTextEdit; +class QTextCursor; class HypothesisTestView : public QWidget { Q_OBJECT @@ -83,6 +84,7 @@ void fillToolBar(QToolBar*); void print(QPrinter*) const; void changed(); + void cursorPositionChanged(); void clearResult(); private slots: }; diff --git a/src/kdefrontend/hypothesisTest/HypothesisTestView.cpp b/src/kdefrontend/hypothesisTest/HypothesisTestView.cpp --- a/src/kdefrontend/hypothesisTest/HypothesisTestView.cpp +++ b/src/kdefrontend/hypothesisTest/HypothesisTestView.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -58,7 +58,7 @@ HypothesisTestView::HypothesisTestView(HypothesisTest* hypothesisTest) : QWidget(), m_hypothesisTest(hypothesisTest), m_testName(new QLabel()), - m_statsTable(new QTextEdit()), + m_statsTable(new QTextEdit()), m_summaryResults(new QWidget()) { m_statsTable->setReadOnly(true); @@ -77,8 +77,11 @@ initActions(); initMenus(); + m_statsTable->setMouseTracking(true); + // m_summaryResults->setStyleSheet("background-color:white; border: 0px; margin: 0px; padding 0px;qproperty-frame: false;"); connect(m_hypothesisTest, &HypothesisTest::changed, this, &HypothesisTestView::changed); + connect(m_statsTable, &QTextEdit::cursorPositionChanged, this, &HypothesisTestView::cursorPositionChanged); } void HypothesisTestView::initActions() { @@ -149,7 +152,20 @@ void HypothesisTestView::changed() { m_testName->setText(m_hypothesisTest->testName()); m_statsTable->setHtml(m_hypothesisTest->statsTable()); - m_summaryResults->setLayout(m_hypothesisTest->summaryLayout()); + m_summaryResults->setLayout(m_hypothesisTest->summaryLayout()); + } + + void HypothesisTestView::cursorPositionChanged() { + QTextCursor cursor = m_statsTable->textCursor(); + cursor.select(QTextCursor::WordUnderCursor); + QMap* tooltips = m_hypothesisTest->tooltips(); + if (!cursor.selectedText().isEmpty()) + QToolTip::showText(QCursor::pos(), + QString("%1 %2") + .arg(cursor.selectedText()) + .arg(tooltips->value(cursor.selectedText()))); + else + QToolTip::hideText(); } void HypothesisTestView::exportToFile(const QString& path, const bool exportHeader, const QString& separator, QLocale::Language language) const {