diff --git a/src/backend/generalTest/CorrelationCoefficient.cpp b/src/backend/generalTest/CorrelationCoefficient.cpp --- a/src/backend/generalTest/CorrelationCoefficient.cpp +++ b/src/backend/generalTest/CorrelationCoefficient.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,11 @@ m_correlationValue = 0; m_statisticValue.clear(); m_pValue.clear(); + m_statsTable2->clear(); + + for (int i = 0; i < 50; i++) + m_tooltips2[i]->clear(); + for (int i = 0; i < RESULTLINESCOUNT; i++) m_resultLine[i]->clear(); @@ -194,6 +200,40 @@ sqrt((N * sumSqCol1 - gsl_pow_2(sumCol1)) * (N * sumSqCol2 - gsl_pow_2(sumCol2))); + // printing table; + // cell constructor structure; data, level, rowSpanCount, m_columnspanCount, isHeader; + QList rowMajor2; + for (int i = 0; i < 50; i++) + m_tooltips2[i]->clear(); + int level2 = 0; + int itr = 0; + + // horizontal header + QString sigma2 = UTF8_QSTRING("Σ"); + rowMajor2.append(new Cell2("", level2, true)); + + rowMajor2.append(new Cell2("N", level2, true, m_tooltips2[itr++], "Total Number of Observations", 1, 1, true)); + rowMajor2.append(new Cell2(QString(sigma2 + "Scores"), level2, true, m_tooltips2[itr++], "Sum of Scores in each column")); + rowMajor2.append(new Cell2(QString(sigma2 + "Scores2"), level2, true, m_tooltips2[itr++], "Sum of Squares of scores in each column")); + rowMajor2.append(new Cell2(QString(sigma2 + "(" + UTF8_QSTRING("∏") + "Scores)"), level2, true, m_tooltips2[itr++], "Sum of product of scores of both columns")); + + //data with vertical header. + level2++; + rowMajor2.append(new Cell2(col1Name, level2, true)); + rowMajor2.append(new Cell2(N, level2)); + rowMajor2.append(new Cell2(sumCol1, level2)); + rowMajor2.append(new Cell2(sumSqCol1, level2)); + + rowMajor2.append(new Cell2(sumCol12, level2, false, nullptr, "", 2, 1)); + + level2++; + rowMajor2.append(new Cell2(col2Name, level2, true)); + rowMajor2.append(new Cell2(N, level2)); + rowMajor2.append(new Cell2(sumCol2, level2)); + rowMajor2.append(new Cell2(sumSqCol2, level2)); + + appendHtmlTable4(rowMajor2); + printLine(0, QString("Correlation Value is %1").arg(round(m_correlationValue)), "green"); } @@ -206,6 +246,7 @@ // TODO: add tooltips. // TODO: Compute tauB for ties. // TODO: find P Value from Z Value +// TODO: Program getting crashed for some cases (same coluns). void CorrelationCoefficient::performKendall() { if (m_columns.count() != 2) { printError("Select only 2 columns "); diff --git a/src/backend/generalTest/GeneralTest.h b/src/backend/generalTest/GeneralTest.h --- a/src/backend/generalTest/GeneralTest.h +++ b/src/backend/generalTest/GeneralTest.h @@ -33,11 +33,13 @@ #include "backend/lib/macros.h" #include "kdefrontend/generalTest/GeneralTestView.h" +#include +#include + class Spreadsheet; class QString; class Column; class QVBoxLayout; -class QLabel; class GeneralTest : public AbstractPart { Q_OBJECT @@ -65,6 +67,27 @@ } }; + struct Cell2 { + QLabel* label; + QString data; + int level; + bool isHeader; + int rowSpanCount; + int columnSpanCount; + Cell2(QVariant data = "", int level = 0, bool isHeader = false, QLabel* label = nullptr, QVariant tooltip = "", int rowSpanCount = 1, int columnSpanCount = 1, bool isEditable = false) { + Q_UNUSED(isEditable); + this->label = label; + this->data = data.toString(); + this->level = level; + this->isHeader = isHeader; + this->rowSpanCount = rowSpanCount; + this->columnSpanCount = columnSpanCount; + + if (label != nullptr) + this->label->setToolTip(tooltip.toString()); + } + }; + enum ErrorType {ErrorUnqualSize, ErrorEmptyColumn, NoError}; void setDataSourceType(DataSourceType type); @@ -77,6 +100,7 @@ QStringList allColumns(); QString testName(); QString statsTable(); + QTextEdit* statsTable2(); QMap tooltips(); QVBoxLayout* summaryLayout(); @@ -105,13 +129,15 @@ QVector m_columns; QStringList m_allColumns; - QString m_currTestName; - QString m_statsTable; - QVBoxLayout* m_summaryLayout{nullptr}; QLabel* m_resultLine[RESULTLINESCOUNT]; QMap m_tooltips; + QString m_currTestName; + QString m_statsTable; + QTextEdit* m_statsTable2; + QList m_tooltips2; + QString round(QVariant number, int precision = 3); int findCount(const Column* column); @@ -132,6 +158,7 @@ QString getHtmlTable(int row, int column, QVariant* rowMajor); QString getHtmlTable3(const QList& rowMajor); + void appendHtmlTable4(const QList& rowMajor); QString getLine(const QString& msg, const QString& color = "black"); void printLine(const int& index, const QString& msg, const QString& color = "black"); diff --git a/src/backend/generalTest/GeneralTest.cpp b/src/backend/generalTest/GeneralTest.cpp --- a/src/backend/generalTest/GeneralTest.cpp +++ b/src/backend/generalTest/GeneralTest.cpp @@ -37,6 +37,9 @@ //#include #include #include +#include +#include +#include //#include //#include //#include @@ -51,7 +54,12 @@ GeneralTest::GeneralTest(const QString& name, const AspectType& type) : AbstractPart(name, type), - m_summaryLayout(new QVBoxLayout()) { + m_summaryLayout(new QVBoxLayout()), + m_statsTable2(new QTextEdit()) { + + m_statsTable2->setReadOnly(true); + for (int i = 0; i < 50; i++) + m_tooltips2.append(new QLabel(m_statsTable2)); m_currTestName = i18n("Result Table"); for (int i = 0; i < RESULTLINESCOUNT; i++) { @@ -86,6 +94,11 @@ return m_statsTable; } +QTextEdit* GeneralTest::statsTable2() { + return m_statsTable2; +} + + QMap GeneralTest::tooltips() { return m_tooltips; } @@ -94,7 +107,6 @@ return m_summaryLayout; } - void GeneralTest::setColumns(QStringList cols) { m_columns.clear(); Column* column = new Column("column"); @@ -470,6 +482,63 @@ return table; } +void GeneralTest::appendHtmlTable4(const QList& rowMajor) { + int rowMajorSize = rowMajor.size(); + + if (rowMajorSize == 0) + return; + + QString table; + table = ""; + + table += ""; + + table += " "; + int prevLevel = 0; + QIcon icon = QIcon::fromTheme("dialog-information"); + QPixmap pixmap = icon.pixmap(8, 8); + for (int i = 0; i < rowMajorSize; i++) { + Cell2* currCell = rowMajor[i]; + if (currCell->level != prevLevel) { + table += " "; + table += " "; + prevLevel = currCell->level; + } + QString cellStartTag = ""; + table += "
isHeader) { + cellStartTag = "" + + i18n("%1", currCell->data) + + cellEndTag; + m_statsTable2->setHtml(table); + m_statsTable2->moveCursor(QTextCursor::End); + + const QRect qRect = m_statsTable2->cursorRect(); +// QDEBUG("qrect top is " << qRect.top() << "left is " << qRect.left()); + if (currCell->label != nullptr) { +// currCell->label->setPixmap(pixmap); + currCell->label->setText("i"); + currCell->label->move(qRect.left(), qRect.top() + 1); + } + } + table += "
"; + m_statsTable2->setHtml(table); +} + QString GeneralTest::getLine(const QString& msg, const QString& color) { return "

" + i18n("%1", msg) + "

"; } @@ -558,3 +627,10 @@ // emit requestProjectContextMenu(menu); return menu; } + +bool operator <(QPoint point1, QPoint point2) { + Q_UNUSED(point1); + Q_UNUSED(point2); + // Do you logic here, to compare two points. + return true; +} diff --git a/src/kdefrontend/generalTest/GeneralTestView.h b/src/kdefrontend/generalTest/GeneralTestView.h --- a/src/kdefrontend/generalTest/GeneralTestView.h +++ b/src/kdefrontend/generalTest/GeneralTestView.h @@ -70,6 +70,7 @@ GeneralTest* m_generalTest; QLabel* m_testName; QTextEdit* m_statsTable; + QTextEdit* m_statsTable2; QWidget* m_summaryResults{nullptr}; QLabel* m_resultLine[RESULTLINESCOUNT]; diff --git a/src/kdefrontend/generalTest/GeneralTestView.cpp b/src/kdefrontend/generalTest/GeneralTestView.cpp --- a/src/kdefrontend/generalTest/GeneralTestView.cpp +++ b/src/kdefrontend/generalTest/GeneralTestView.cpp @@ -57,6 +57,7 @@ m_statsTable(new QTextEdit()), m_summaryResults(new QWidget()) { + m_statsTable2 = GeneralTest->statsTable2(); m_statsTable->setReadOnly(true); m_testName->setStyleSheet("background-color: white"); @@ -71,9 +72,11 @@ layout->addWidget(m_testName); layout->addWidget(m_statsTable); + layout->addWidget(m_statsTable2); layout->addWidget(m_summaryResults); layout->addStretch(1); init(); + } GeneralTestView::~GeneralTestView() { @@ -157,6 +160,11 @@ m_testName->show(); m_summaryResults->show(); + if (m_statsTable2->toPlainText().isEmpty()) + m_statsTable2->hide(); + else + m_statsTable2->show(); + if (m_generalTest->statsTable().isEmpty()) m_statsTable->hide(); else { @@ -168,6 +176,14 @@ } void GeneralTestView::cursorPositionChanged() { +// QMap::iterator itr; +// for (itr = m_generalTest->tooltips2().begin(); itr != m_generalTest->tooltips2().end(); itr++) { +// if (!itr.key().isNull()) +// QToolTip::showText(itr.key(), +// QString("%1") +// .arg(itr.value())); +// } + QTextCursor cursor = m_statsTable->textCursor(); cursor.select(QTextCursor::LineUnderCursor); QMap tooltips = m_generalTest->tooltips();