improved jkqtmathtext_test with the ability to enter user-editable text and output of parse/size/render times

This commit is contained in:
jkriege2 2018-12-05 23:03:21 +01:00
parent 1cec52a373
commit f7dcaa926d
3 changed files with 178 additions and 53 deletions

View File

@ -110,6 +110,7 @@ TestForm::TestForm(QWidget *parent) :
ui->cmbTestset->addItem(QLatin1String("Schrödinger's equation"), "$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$"); ui->cmbTestset->addItem(QLatin1String("Schrödinger's equation"), "$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
ui->cmbTestset->addItem("Cauchy-Schwarz inequality", "$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$"); ui->cmbTestset->addItem("Cauchy-Schwarz inequality", "$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$");
ui->cmbTestset->addItem("Maxwell's equations", "$\\begin{aligned}\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \\end{aligned}$"); ui->cmbTestset->addItem("Maxwell's equations", "$\\begin{aligned}\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \\end{aligned}$");
ui->cmbTestset->addItem("User-Editable Text");
//ui->cmbTestset->addItem("", "$$"); //ui->cmbTestset->addItem("", "$$");
//ui->cmbTestset->addItem("", "$$"); //ui->cmbTestset->addItem("", "$$");
//ui->cmbTestset->addItem("", "$$"); //ui->cmbTestset->addItem("", "$$");
@ -132,7 +133,7 @@ TestForm::~TestForm()
double TestForm::draw(QPainter& painter, double X, double YY, JKQTmathText& mt, QString name) { double TestForm::draw(QPainter& painter, double X, double YY, JKQTmathText& mt, QString name, double& durationSizingMS, double&durationTimingMS) {
double Y=YY; double Y=YY;
@ -140,7 +141,8 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTmathText& mt,
ht.start(); ht.start();
QSizeF s=mt.getSize(painter); QSizeF s=mt.getSize(painter);
Y=Y+mt.getAscent(painter); Y=Y+mt.getAscent(painter);
qDebug()<<" sizing in "<<ht.get_time()/1000.0<<" ms\n"; durationSizingMS=ht.get_time()/1000.0;
qDebug()<<" sizing in "<<durationSizingMS<<" ms\n";
QPen p=painter.pen(); QPen p=painter.pen();
p.setColor("lightcoral"); p.setColor("lightcoral");
p.setStyle(Qt::DashLine); p.setStyle(Qt::DashLine);
@ -157,7 +159,8 @@ double TestForm::draw(QPainter& painter, double X, double YY, JKQTmathText& mt,
p.setColor("black"); p.setColor("black");
painter.setPen(p); painter.setPen(p);
mt.draw(painter, X, Y, ui->chkBoxes->isChecked()); mt.draw(painter, X, Y, ui->chkBoxes->isChecked());
qDebug()<<" drawing in "<<ht.get_time()/1000.0<<" ms"; durationTimingMS=ht.get_time()/1000.0;
qDebug()<<" drawing in "<<durationTimingMS<<" ms";
p.setColor("blue"); p.setColor("blue");
painter.setPen(p); painter.setPen(p);
@ -188,7 +191,7 @@ QTreeWidgetItem *TestForm::createTree(JKQTmathText::MTnode *node, QTreeWidgetIte
JKQTmathText::MTmatrixNode* matrixN=dynamic_cast<JKQTmathText::MTmatrixNode*>(node); JKQTmathText::MTmatrixNode* matrixN=dynamic_cast<JKQTmathText::MTmatrixNode*>(node);
JKQTmathText::MTdecoratedNode* decoN=dynamic_cast<JKQTmathText::MTdecoratedNode*>(node); JKQTmathText::MTdecoratedNode* decoN=dynamic_cast<JKQTmathText::MTdecoratedNode*>(node);
QTreeWidgetItem* ti=NULL; QTreeWidgetItem* ti=nullptr;
if (parent) ti=new QTreeWidgetItem(parent); if (parent) ti=new QTreeWidgetItem(parent);
else ti=new QTreeWidgetItem(ui->tree); else ti=new QTreeWidgetItem(ui->tree);
@ -202,7 +205,7 @@ QTreeWidgetItem *TestForm::createTree(JKQTmathText::MTnode *node, QTreeWidgetIte
QVector<QVector<JKQTmathText::MTnode*> > children=matrixN->get_children(); QVector<QVector<JKQTmathText::MTnode*> > children=matrixN->get_children();
for (int y=0; y<l; y++) { for (int y=0; y<l; y++) {
for (int x=0; x<c; x++) { for (int x=0; x<c; x++) {
if (children[y].at(x)!=NULL) { if (children[y].at(x)!=nullptr) {
QTreeWidgetItem* it=createTree(children[y].at(x), ti); QTreeWidgetItem* it=createTree(children[y].at(x), ti);
it->setText(0, QString("(%1,%2):").arg(y).arg(x)+it->text(0)); it->setText(0, QString("(%1,%2):").arg(y).arg(x)+it->text(0));
ti->addChild(it); ti->addChild(it);
@ -274,9 +277,16 @@ void TestForm::updateMath()
//QString text="x_0My Text$\\sqrt{a^2+b^2 } \\underbrace{underbrace}{x_0}$"; //QString text="x_0My Text$\\sqrt{a^2+b^2 } \\underbrace{underbrace}{x_0}$";
if (ui->cmbTestset->currentIndex()==ui->cmbTestset->count()-1) {
mathTest=ui->textBrowserSource->toPlainText();
ui->textBrowserSource->setReadOnly(false);
ui->btnRender->setEnabled(true);
} else {
mathTest=ui->cmbTestset->itemData(ui->cmbTestset->currentIndex()).toString(); mathTest=ui->cmbTestset->itemData(ui->cmbTestset->currentIndex()).toString();
ui->textBrowserSource->setPlainText(mathTest); ui->textBrowserSource->setPlainText(mathTest);
ui->textBrowserSource->setReadOnly(true);
ui->btnRender->setEnabled(false);
}
ui->scrollArea->setBackgroundRole(QPalette::Dark); ui->scrollArea->setBackgroundRole(QPalette::Dark);
@ -313,24 +323,32 @@ void TestForm::updateMath()
} }
ui->tree->clear(); ui->tree->clear();
ht.start();
double durationParse=0;
if (mt.parse(mathTest)) { if (mt.parse(mathTest)) {
durationParse=ht.get_time()/1000.0;
ui->tree->addTopLevelItem(createTree(mt.get_parsedNode())); ui->tree->addTopLevelItem(createTree(mt.get_parsedNode()));
} else {
durationParse=ht.get_time()/1000.0;
} }
ui->labParsingTimes->setText(QString(" %1ms").arg(durationParse, 0, 'f', 3));
ui->tree->expandAll(); ui->tree->expandAll();
bool okh=true; bool okh=true;
ui->textBrowser->clear(); ui->textBrowser->clear();
qDebug()<<"parse mathTest in "<<ht.get_time()/1000.0<<" ms\n"; qDebug()<<"parse mathTest in "<<ht.get_time()/1000.0<<" ms\n";
QStringList sl=ui->edtSizes->text().split(","); QStringList sl=ui->edtSizes->text().split(",");
ui->labRenderTimes->setText("");
for (int i=0; i<sl.size(); i++) { for (int i=0; i<sl.size(); i++) {
bool ok=true; bool ok=true;
int size=sl[i].trimmed().toUInt(&ok); int size=sl[i].trimmed().toUInt(&ok);
if (!ok) size=10+i*5; if (!ok) size=10+i*5;
mt.set_fontSize(size); mt.set_fontSize(size);
Y+=draw(painter, X1, Y, mt, QString("%1, %2, %3pt").arg(ui->cmbTestset->currentText()).arg(ui->cmbFont->currentText()).arg(size)); double durationSizingMS=0, durationTimingMS=0;
Y+=draw(painter, X1, Y, mt, QString("%1, %2, %3pt").arg(ui->cmbTestset->currentText()).arg(ui->cmbFont->currentText()).arg(size), durationSizingMS, durationTimingMS);
ui->labRenderTimes->setText(ui->labRenderTimes->text()+QString(" %1pt: %2ms/%3ms").arg(size).arg(durationSizingMS, 0, 'F', 1).arg(durationTimingMS, 0, 'F', 1));
ui->textBrowser->textCursor().insertHtml("<hr>"+mt.toHtml(&okh)+"<hr><br><br>"); ui->textBrowser->textCursor().insertHtml("<hr>"+mt.toHtml(&okh)+"<hr><br><br>");
qDebug()<<"HTML: ---------------------------------------------\n"<<mt.toHtml(&okh)<<"\nHTML: --------------------------------------------- ok="<<okh; qDebug()<<"HTML: ---------------------------------------------\n"<<mt.toHtml(&okh)<<"\nHTML: --------------------------------------------- ok="<<okh;
if (mt.get_error_list().size()>0) { if (mt.get_error_list().size()>0) {

View File

@ -26,7 +26,7 @@ class TestForm : public QWidget
private: private:
Ui::TestForm *ui; Ui::TestForm *ui;
JKQTPHighResTimer ht; JKQTPHighResTimer ht;
double draw(QPainter& painter, double X, double YY, JKQTmathText& mt, QString name); double draw(QPainter& painter, double X, double YY, JKQTmathText& mt, QString name, double &durationSizingMS, double &durationTimingMS);
QTreeWidgetItem* createTree(JKQTmathText::MTnode* node, QTreeWidgetItem *parent=NULL); QTreeWidgetItem* createTree(JKQTmathText::MTnode* node, QTreeWidgetItem *parent=NULL);
}; };

View File

@ -14,7 +14,7 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" rowspan="5"> <item row="4" column="0" rowspan="11">
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
@ -25,7 +25,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>605</width> <width>605</width>
<height>628</height> <height>616</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
@ -43,10 +43,16 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="11" column="1">
<widget class="QTextBrowser" name="textBrowserSource"> <widget class="QLabel" name="label_12">
<property name="verticalScrollBarPolicy"> <property name="font">
<enum>Qt::ScrollBarAlwaysOff</enum> <font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>render times (getSize()+getAscent()/draw()):</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -186,6 +192,86 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="15" column="0" colspan="2">
<widget class="JKQTMathTextLabel" name="labMath">
<property name="text">
<string>left(left[sqrt{2picdotint_{-infty}^infty f(x);mathrm{d}x}right]right) </string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>LaTeX source:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnRender">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Render</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1" rowspan="2">
<widget class="QPlainTextEdit" name="textBrowserSource">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>rendered result:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_9">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>HTML output:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
@ -266,7 +352,17 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="12" column="1">
<widget class="QLabel" name="labRenderTimes">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="1"> <item row="8" column="1">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item row="14" column="1">
<widget class="QTreeWidget" name="tree"> <widget class="QTreeWidget" name="tree">
<property name="headerHidden"> <property name="headerHidden">
<bool>true</bool> <bool>true</bool>
@ -278,41 +374,36 @@
</column> </column>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="13" column="1">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_9">
<property name="text">
<string>HTML output:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="label_10">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text"> <property name="text">
<string>node tree:</string> <string>node tree:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="9" column="1">
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_13">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text"> <property name="text">
<string>LaTeX source:</string> <string>parsing times:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="10" column="1">
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="labParsingTimes">
<property name="text"> <property name="text">
<string>rendered result:</string> <string/>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="JKQTMathTextLabel" name="labMath">
<property name="text">
<string>left(left[sqrt{2picdotint_{-infty}^infty f(x);mathrm{d}x}right]right) </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -366,7 +457,7 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>591</x> <x>790</x>
<y>27</y> <y>27</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -382,7 +473,7 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>669</x> <x>868</x>
<y>27</y> <y>27</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -398,7 +489,7 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>765</x> <x>964</x>
<y>27</y> <y>27</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -414,7 +505,7 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>867</x> <x>1067</x>
<y>27</y> <y>27</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -430,7 +521,7 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>520</x> <x>679</x>
<y>29</y> <y>29</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@ -510,8 +601,8 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>697</x> <x>949</x>
<y>45</y> <y>57</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>518</x> <x>518</x>
@ -526,8 +617,8 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>941</x> <x>1221</x>
<y>54</y> <y>57</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>520</x> <x>520</x>
@ -542,8 +633,8 @@
<slot>updateMath()</slot> <slot>updateMath()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>905</x> <x>1181</x>
<y>22</y> <y>27</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>519</x> <x>519</x>
@ -551,6 +642,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>btnRender</sender>
<signal>clicked()</signal>
<receiver>TestForm</receiver>
<slot>updateMath()</slot>
<hints>
<hint type="sourcelabel">
<x>1187</x>
<y>83</y>
</hint>
<hint type="destinationlabel">
<x>617</x>
<y>380</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>updateMath()</slot> <slot>updateMath()</slot>