Changeset View
Changeset View
Standalone View
Standalone View
src/worksheet.cpp
Show First 20 Lines • Show All 262 Lines • ▼ Show 20 Line(s) | 262 | { | |||
---|---|---|---|---|---|
263 | return !m_firstEntry; | 263 | return !m_firstEntry; | ||
264 | } | 264 | } | ||
265 | 265 | | |||
266 | bool Worksheet::isLoadingFromFile() | 266 | bool Worksheet::isLoadingFromFile() | ||
267 | { | 267 | { | ||
268 | return m_isLoadingFromFile; | 268 | return m_isLoadingFromFile; | ||
269 | } | 269 | } | ||
270 | 270 | | |||
271 | bool Worksheet::isReadOnly() const | ||||
272 | { | ||||
273 | return m_readOnly; | ||||
274 | } | ||||
275 | | ||||
271 | void Worksheet::makeVisible(WorksheetEntry* entry) | 276 | void Worksheet::makeVisible(WorksheetEntry* entry) | ||
272 | { | 277 | { | ||
273 | QRectF r = entry->boundingRect(); | 278 | QRectF r = entry->boundingRect(); | ||
274 | r = entry->mapRectToScene(r); | 279 | r = entry->mapRectToScene(r); | ||
275 | r.adjust(0, -10, 0, 10); | 280 | r.adjust(0, -10, 0, 10); | ||
276 | worksheetView()->makeVisible(r); | 281 | worksheetView()->makeVisible(r); | ||
277 | } | 282 | } | ||
278 | 283 | | |||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Line(s) | 468 | if (m_placeholderEntry) { | |||
468 | m_placeholderEntry = nullptr; | 473 | m_placeholderEntry = nullptr; | ||
469 | } | 474 | } | ||
470 | m_dragEntry = nullptr; | 475 | m_dragEntry = nullptr; | ||
471 | } | 476 | } | ||
472 | 477 | | |||
473 | void Worksheet::evaluate() | 478 | void Worksheet::evaluate() | ||
474 | { | 479 | { | ||
475 | qDebug()<<"evaluate worksheet"; | 480 | qDebug()<<"evaluate worksheet"; | ||
476 | if (!m_loginDone) | 481 | if (!m_loginDone && !m_readOnly) | ||
477 | loginToSession(); | 482 | loginToSession(); | ||
478 | 483 | | |||
479 | firstEntry()->evaluate(WorksheetEntry::EvaluateNext); | 484 | firstEntry()->evaluate(WorksheetEntry::EvaluateNext); | ||
480 | 485 | | |||
481 | emit modified(); | 486 | emit modified(); | ||
482 | } | 487 | } | ||
483 | 488 | | |||
484 | void Worksheet::evaluateCurrentEntry() | 489 | void Worksheet::evaluateCurrentEntry() | ||
485 | { | 490 | { | ||
486 | if (!m_loginDone) | 491 | if (!m_readOnly && !m_loginDone) | ||
487 | loginToSession(); | 492 | loginToSession(); | ||
488 | 493 | | |||
489 | WorksheetEntry* entry = currentEntry(); | 494 | WorksheetEntry* entry = currentEntry(); | ||
490 | if(!entry) | 495 | if(!entry) | ||
491 | return; | 496 | return; | ||
492 | entry->evaluateCurrentItem(); | 497 | entry->evaluateCurrentItem(); | ||
493 | } | 498 | } | ||
494 | 499 | | |||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Line(s) | |||||
790 | 795 | | |||
791 | void Worksheet::enableHighlighting(bool highlight) | 796 | void Worksheet::enableHighlighting(bool highlight) | ||
792 | { | 797 | { | ||
793 | if(highlight) | 798 | if(highlight) | ||
794 | { | 799 | { | ||
795 | if(m_highlighter) | 800 | if(m_highlighter) | ||
796 | m_highlighter->deleteLater(); | 801 | m_highlighter->deleteLater(); | ||
797 | 802 | | |||
803 | if (!m_readOnly) | ||||
798 | m_highlighter=session()->syntaxHighlighter(this); | 804 | m_highlighter=session()->syntaxHighlighter(this); | ||
805 | else | ||||
806 | m_highlighter=nullptr; | ||||
799 | if(!m_highlighter) | 807 | if(!m_highlighter) | ||
800 | m_highlighter=new Cantor::DefaultHighlighter(this); | 808 | m_highlighter=new Cantor::DefaultHighlighter(this); | ||
801 | 809 | | |||
802 | connect(m_highlighter, SIGNAL(rulesChanged()), this, SLOT(rehighlight())); | 810 | connect(m_highlighter, SIGNAL(rulesChanged()), this, SLOT(rehighlight())); | ||
803 | 811 | | |||
804 | }else | 812 | }else | ||
805 | { | 813 | { | ||
806 | if(m_highlighter) | 814 | if(m_highlighter) | ||
Show All 11 Lines | |||||
818 | 826 | | |||
819 | Cantor::Session* Worksheet::session() | 827 | Cantor::Session* Worksheet::session() | ||
820 | { | 828 | { | ||
821 | return m_session; | 829 | return m_session; | ||
822 | } | 830 | } | ||
823 | 831 | | |||
824 | bool Worksheet::isRunning() | 832 | bool Worksheet::isRunning() | ||
825 | { | 833 | { | ||
826 | return m_session->status()==Cantor::Session::Running; | 834 | return (m_readOnly ? false : m_session->status()==Cantor::Session::Running); | ||
827 | } | 835 | } | ||
828 | 836 | | |||
829 | bool Worksheet::showExpressionIds() | 837 | bool Worksheet::showExpressionIds() | ||
830 | { | 838 | { | ||
831 | return m_showExpressionIds; | 839 | return m_showExpressionIds; | ||
832 | } | 840 | } | ||
833 | 841 | | |||
834 | bool Worksheet::animationsEnabled() | 842 | bool Worksheet::animationsEnabled() | ||
Show All 11 Lines | 853 | { | |||
846 | m_showExpressionIds=enable; | 854 | m_showExpressionIds=enable; | ||
847 | emit updatePrompt(); | 855 | emit updatePrompt(); | ||
848 | } | 856 | } | ||
849 | 857 | | |||
850 | QDomDocument Worksheet::toXML(KZip* archive) | 858 | QDomDocument Worksheet::toXML(KZip* archive) | ||
851 | { | 859 | { | ||
852 | QDomDocument doc( QLatin1String("CantorWorksheet") ); | 860 | QDomDocument doc( QLatin1String("CantorWorksheet") ); | ||
853 | QDomElement root=doc.createElement( QLatin1String("Worksheet") ); | 861 | QDomElement root=doc.createElement( QLatin1String("Worksheet") ); | ||
854 | root.setAttribute(QLatin1String("backend"), m_session->backend()->name()); | 862 | root.setAttribute(QLatin1String("backend"), (m_session ? m_session->backend()->name(): m_backendName)); | ||
filipesaraiva: Is it working correctly? I tested with Python 3 backend but the line is null: `<Worksheet… | |||||
Good find, Filipe! sirgienko: Good find, Filipe!
I forget, that for created session (which, obviciously not loaded)… | |||||
855 | doc.appendChild(root); | 863 | doc.appendChild(root); | ||
856 | 864 | | |||
857 | for( WorksheetEntry* entry = firstEntry(); entry; entry = entry->next()) | 865 | for( WorksheetEntry* entry = firstEntry(); entry; entry = entry->next()) | ||
858 | { | 866 | { | ||
859 | QDomElement el = entry->toXml(doc, archive); | 867 | QDomElement el = entry->toXml(doc, archive); | ||
860 | root.appendChild( el ); | 868 | root.appendChild( el ); | ||
861 | } | 869 | } | ||
862 | return doc; | 870 | return doc; | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | |||||
977 | { | 985 | { | ||
978 | QFile file(filename); | 986 | QFile file(filename); | ||
979 | if (!file.open(QIODevice::ReadOnly)) { | 987 | if (!file.open(QIODevice::ReadOnly)) { | ||
980 | KMessageBox::error(worksheetView(), i18n("Couldn't open the file %1", filename), i18n("Cantor")); | 988 | KMessageBox::error(worksheetView(), i18n("Couldn't open the file %1", filename), i18n("Cantor")); | ||
981 | return false; | 989 | return false; | ||
982 | } | 990 | } | ||
983 | 991 | | |||
984 | bool rc = load(&file); | 992 | bool rc = load(&file); | ||
985 | if (rc) | 993 | if (rc && !m_readOnly) | ||
986 | m_session->setWorksheetPath(filename); | 994 | m_session->setWorksheetPath(filename); | ||
987 | 995 | | |||
988 | return rc; | 996 | return rc; | ||
989 | } | 997 | } | ||
990 | 998 | | |||
991 | void Worksheet::load(QByteArray* data) | 999 | void Worksheet::load(QByteArray* data) | ||
992 | { | 1000 | { | ||
993 | QBuffer buf(data); | 1001 | QBuffer buf(data); | ||
Show All 23 Lines | 1006 | { | |||
1017 | QByteArray data = content->data(); | 1025 | QByteArray data = content->data(); | ||
1018 | 1026 | | |||
1019 | // qDebug()<<"read: "<<data; | 1027 | // qDebug()<<"read: "<<data; | ||
1020 | 1028 | | |||
1021 | QDomDocument doc; | 1029 | QDomDocument doc; | ||
1022 | doc.setContent(data); | 1030 | doc.setContent(data); | ||
1023 | QDomElement root=doc.documentElement(); | 1031 | QDomElement root=doc.documentElement(); | ||
1024 | // qDebug()<<root.tagName(); | 1032 | // qDebug()<<root.tagName(); | ||
1025 | 1033 | | |||
1026 | const QString backendName=root.attribute(QLatin1String("backend")); | 1034 | m_backendName=root.attribute(QLatin1String("backend")); | ||
asemke: use already here m_backendName directly? | |||||
sirgienko: Good idea. | |||||
1027 | Cantor::Backend* b=Cantor::Backend::createBackend(backendName); | 1035 | Cantor::Backend* b=Cantor::Backend::createBackend(m_backendName); | ||
1028 | if (!b) | 1036 | if (!b) | ||
1029 | { | 1037 | { | ||
1030 | QApplication::restoreOverrideCursor(); | 1038 | QApplication::restoreOverrideCursor(); | ||
1031 | KMessageBox::error(worksheetView(), i18n("The backend with which this file was generated is not installed. It needs %1", backendName), i18n("Cantor")); | 1039 | KMessageBox::information(worksheetView(), i18n("%1 backend was not found. Editing and executing command entries is not possible", m_backendName), i18n("Cantor")); | ||
1032 | return false; | 1040 | m_readOnly = true; | ||
1033 | } | 1041 | } | ||
1042 | else | ||||
1043 | m_readOnly = false; | ||||
1034 | 1044 | | |||
1035 | if(!b->isEnabled()) | 1045 | if(!m_readOnly && !b->isEnabled()) | ||
1036 | { | 1046 | { | ||
1037 | QApplication::restoreOverrideCursor(); | 1047 | QApplication::restoreOverrideCursor(); | ||
1038 | KMessageBox::information(worksheetView(), i18n("There are some problems with the %1 backend,\n"\ | 1048 | KMessageBox::information(worksheetView(), i18n("There are some problems with the %1 backend,\n"\ | ||
1039 | "please check your configuration or install the needed packages.\n" | 1049 | "please check your configuration or install the needed packages.\n" | ||
1040 | "You will only be able to view this worksheet.", backendName), i18n("Cantor")); | 1050 | "You will only be able to view this worksheet.", m_backendName), i18n("Cantor")); | ||
1041 | 1051 | | |||
1042 | } | 1052 | } | ||
1043 | 1053 | | |||
1044 | m_isLoadingFromFile = true; | 1054 | m_isLoadingFromFile = true; | ||
1045 | 1055 | | |||
1046 | //cleanup the worksheet and all it contains | 1056 | //cleanup the worksheet and all it contains | ||
1047 | delete m_session; | 1057 | delete m_session; | ||
1048 | m_session=nullptr; | 1058 | m_session=nullptr; | ||
1049 | m_loginDone = false; | 1059 | m_loginDone = false; | ||
1050 | 1060 | | |||
1051 | //file can only be loaded in a worksheet that was not eidted/modified yet (s.a. CantorShell::load()) | 1061 | //file can only be loaded in a worksheet that was not eidted/modified yet (s.a. CantorShell::load()) | ||
1052 | //in this case on the default "first entry" is available -> delete it. | 1062 | //in this case on the default "first entry" is available -> delete it. | ||
1053 | if (m_firstEntry) { | 1063 | if (m_firstEntry) { | ||
1054 | delete m_firstEntry; | 1064 | delete m_firstEntry; | ||
1055 | m_firstEntry = nullptr; | 1065 | m_firstEntry = nullptr; | ||
1056 | } | 1066 | } | ||
1057 | 1067 | | |||
1058 | 1068 | | |||
1069 | if (!m_readOnly) | ||||
1059 | m_session=b->createSession(); | 1070 | m_session=b->createSession(); | ||
1060 | 1071 | | |||
1061 | qDebug()<<"loading entries"; | 1072 | qDebug()<<"loading entries"; | ||
1062 | QDomElement expressionChild = root.firstChildElement(); | 1073 | QDomElement expressionChild = root.firstChildElement(); | ||
1063 | WorksheetEntry* entry = nullptr; | 1074 | WorksheetEntry* entry = nullptr; | ||
1064 | while (!expressionChild.isNull()) { | 1075 | while (!expressionChild.isNull()) { | ||
1065 | QString tag = expressionChild.tagName(); | 1076 | QString tag = expressionChild.tagName(); | ||
1066 | if (tag == QLatin1String("Expression")) | 1077 | if (tag == QLatin1String("Expression")) | ||
Show All 24 Lines | |||||
1091 | } | 1102 | } | ||
1092 | 1103 | | |||
1093 | expressionChild = expressionChild.nextSiblingElement(); | 1104 | expressionChild = expressionChild.nextSiblingElement(); | ||
1094 | } | 1105 | } | ||
1095 | 1106 | | |||
1096 | m_isLoadingFromFile = false; | 1107 | m_isLoadingFromFile = false; | ||
1097 | 1108 | | |||
1098 | //Set the Highlighting, depending on the current state | 1109 | //Set the Highlighting, depending on the current state | ||
1099 | //If the session isn't logged in, use the default | 1110 | //If the session isn't logged in or readonly, use the default | ||
1100 | enableHighlighting( m_highlighter!=nullptr || Settings::highlightDefault() ); | 1111 | enableHighlighting( m_highlighter!=nullptr || Settings::highlightDefault() ); | ||
asemke: No syntax highlighting for a saved worksheet in the read only mode? | |||||
Highlighting, even from KSyntaxHighlighting, contains in plugin. sirgienko: Highlighting, even from KSyntaxHighlighting, contains in plugin.
So, no plugin - no… | |||||
1101 | 1112 | | |||
1102 | emit loaded(); | 1113 | emit loaded(); | ||
1103 | return true; | 1114 | return true; | ||
1104 | } | 1115 | } | ||
1105 | 1116 | | |||
1106 | void Worksheet::gotResult(Cantor::Expression* expr) | 1117 | void Worksheet::gotResult(Cantor::Expression* expr) | ||
1107 | { | 1118 | { | ||
1108 | if(expr==nullptr) | 1119 | if(expr==nullptr) | ||
▲ Show 20 Lines • Show All 743 Lines • Show Last 20 Lines |
Is it working correctly? I tested with Python 3 backend but the line is null: <Worksheet backend="">.