[education/cantor] src: Wire TOC controls through the shell
Alexander Semke <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit e205a638f753940ecdb58d8f7a3ec9e34df49d97 by Alexander Semke, on behalf of Nanhao Lv.
Committed on 26/07/2026 at 19:50.
Pushed by asemke into branch 'master'.
Wire TOC controls through the shell
M +66 -3 src/cantor.cpp
M +19 -3 src/cantor.h
M +16 -1 src/cantor.kcfg
M +12 -3 src/cantor_part.cpp
M +11 -3 src/cantor_part.h
M +38 -1 src/settings.ui
https://invent.kde.org/education/cantor/-/commit/e205a638f753940ecdb58d8f7a3ec9e34df49d97
diff --git a/src/cantor.cpp b/src/cantor.cpp
index 562afedb..4c0efda2 100644
--- a/src/cantor.cpp
+++ b/src/cantor.cpp
@@ -64,6 +64,12 @@ CantorShell::CantorShell() : KParts::MainWindow(), m_tabWidget(new QTabWidget(th
connect(m_tabWidget, &QTabWidget::currentChanged, this, &CantorShell::activateWorksheet);
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, &CantorShell::closeTab);
+ connect(this, &CantorShell::requestNavigateToTocNode, this, &CantorShell::forwardNavigateToTocNode);
+ connect(this, &CantorShell::requestChangeHierarchyLevel, this, &CantorShell::forwardChangeHierarchyLevel);
+ connect(this, &CantorShell::requestDeleteHierarchyEntry, this, &CantorShell::forwardDeleteHierarchyEntry);
+ connect(this, &CantorShell::requestRenameHierarchyEntry, this, &CantorShell::forwardRenameHierarchyEntry);
+ connect(this, &CantorShell::requestRenamePlot, this, &CantorShell::forwardRenamePlot);
+ connect(this, &CantorShell::requestDeletePlot, this, &CantorShell::forwardDeletePlot);
// apply the saved mainwindow settings, if any, and ask the mainwindow
// to automatically save settings if changed: window size, toolbar
@@ -236,6 +242,60 @@ void CantorShell::optionsConfigureKeys()
dlg.configure( true );
}
+void CantorShell::forwardNavigateToTocNode(const QString& nodeId)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestNavigateToTocNode", Qt::DirectConnection, Q_ARG(QString, nodeId));
+}
+
+void CantorShell::forwardRenameHierarchyEntry(const QString& hierarchyId, const QString& newName)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestRenameHierarchyEntry", Qt::DirectConnection, Q_ARG(QString, hierarchyId), Q_ARG(QString, newName));
+}
+
+void CantorShell::forwardChangeHierarchyLevel(const QString& hierarchyId, int levelDelta)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestChangeHierarchyLevel", Qt::DirectConnection, Q_ARG(QString, hierarchyId), Q_ARG(int, levelDelta));
+}
+
+void CantorShell::forwardDeleteHierarchyEntry(const QString& hierarchyId, bool deleteContents)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestDeleteHierarchyEntry", Qt::DirectConnection, Q_ARG(QString, hierarchyId), Q_ARG(bool, deleteContents));
+}
+
+void CantorShell::forwardRenamePlot(const QString& commandId, const QString& resultId, const QString& newTitle)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestRenamePlot", Qt::DirectConnection, Q_ARG(QString, commandId), Q_ARG(QString, resultId), Q_ARG(QString, newTitle));
+}
+
+void CantorShell::forwardDeletePlot(const QString& commandId, const QString& resultId)
+{
+ if (m_part)
+ QMetaObject::invokeMethod(m_part, "requestDeletePlot", Qt::DirectConnection, Q_ARG(QString, commandId), Q_ARG(QString, resultId));
+}
+
+void CantorShell::handleTocNodesChanged(QVariantList nodes)
+{
+ if (sender() == m_part)
+ Q_EMIT tocNodesChanged(nodes);
+}
+
+void CantorShell::handleCurrentTocNodeChanged(const QString& nodeId)
+{
+ if (sender() == m_part)
+ Q_EMIT currentTocNodeChanged(nodeId);
+}
+
+void CantorShell::handleTocReadOnlyChanged(bool readOnly)
+{
+ if (sender() == m_part)
+ Q_EMIT tocReadOnlyChanged(readOnly);
+}
+
void CantorShell::fileOpen()
{
// this slot is called whenever the File->Open menu is selected,
@@ -370,9 +430,9 @@ void CantorShell::addWorksheet(const QString& backendName)
connect(part, SIGNAL(setCaption(QString,QIcon)), this, SLOT(setTabCaption(QString,QIcon)));
connect(part, SIGNAL(worksheetSave(QUrl)), this, SLOT(onWorksheetSave(QUrl)));
connect(part, SIGNAL(showHelp(QString)), this, SIGNAL(showHelp(QString)));
- connect(part, SIGNAL(hierarchyChanged(QStringList, QStringList, QList<int>)), this, SIGNAL(hierarchyChanged(QStringList, QStringList, QList<int>)));
- connect(part, SIGNAL(hierarhyEntryNameChange(QString, QString, int)), this, SIGNAL(hierarhyEntryNameChange(QString, QString, int)));
- connect(this, SIGNAL(requestScrollToHierarchyEntry(QString)), part, SIGNAL(requestScrollToHierarchyEntry(QString)));
+ connect(part, SIGNAL(tocNodesChanged(QVariantList)), this, SLOT(handleTocNodesChanged(QVariantList)));
+ connect(part, SIGNAL(currentTocNodeChanged(QString)), this, SLOT(handleCurrentTocNodeChanged(QString)));
+ connect(part, SIGNAL(tocReadOnlyChanged(bool)), this, SLOT(handleTocReadOnlyChanged(bool)));
connect(this, SIGNAL(settingsChanges()), part, SIGNAL(settingsChanges()));
connect(part, SIGNAL(requestDocumentation(QString)), this, SIGNAL(requestDocumentation(QString)));
@@ -475,6 +535,9 @@ void CantorShell::activateWorksheet(int index)
updateWindowTitle(m_part->url().fileName(), m_part->isModified());
updatePanel();
+
+ Q_EMIT tocReadOnlyChanged(!m_part->isReadWrite());
+ QMetaObject::invokeMethod(m_part, "requestTocNodeSnapshot", Qt::QueuedConnection);
}
else
qDebug()<<"selected part doesn't exist";
diff --git a/src/cantor.h b/src/cantor.h
index 7dedac01..9fd7880d 100644
--- a/src/cantor.h
+++ b/src/cantor.h
@@ -14,6 +14,7 @@
#include <QList>
#include <QStringList>
#include <QMap>
+#include <QVariantList>
#include "lib/panelpluginhandler.h"
#include "lib/panelplugin.h"
@@ -66,9 +67,15 @@ protected:
Q_SIGNALS:
void showHelp(QString);
- void hierarchyChanged(QStringList, QStringList, QList<int>);
- void hierarhyEntryNameChange(QString, QString, int);
- void requestScrollToHierarchyEntry(QString);
+ void tocNodesChanged(QVariantList);
+ void currentTocNodeChanged(QString);
+ void requestNavigateToTocNode(QString nodeId);
+ void requestRenameHierarchyEntry(QString hierarchyId, QString newName);
+ void requestChangeHierarchyLevel(QString hierarchyId, int levelDelta);
+ void requestDeleteHierarchyEntry(QString hierarchyId, bool deleteContents);
+ void requestRenamePlot(QString commandId, QString resultId, QString newTitle);
+ void requestDeletePlot(QString commandId, QString resultId);
+ void tocReadOnlyChanged(bool readOnly);
void settingsChanges();
void requestDocumentation(const QString&);
@@ -87,6 +94,15 @@ private Q_SLOTS:
void setTabCaption(const QString&, const QIcon&);
void updateBackendForPart(const QString&);
+ void forwardNavigateToTocNode(const QString& nodeId);
+ void forwardRenameHierarchyEntry(const QString& hierarchyId, const QString& newName);
+ void forwardChangeHierarchyLevel(const QString& hierarchyId, int levelDelta);
+ void forwardDeleteHierarchyEntry(const QString& hierarchyId, bool deleteContents);
+ void forwardRenamePlot(const QString& commandId, const QString& resultId, const QString& newTitle);
+ void forwardDeletePlot(const QString& commandId, const QString& resultId);
+ void handleTocNodesChanged(QVariantList nodes);
+ void handleCurrentTocNodeChanged(const QString& nodeId);
+ void handleTocReadOnlyChanged(bool readOnly);
void closeTab(int index = -1);
void showSettings();
diff --git a/src/cantor.kcfg b/src/cantor.kcfg
index a25fd3e0..333b6b76 100644
--- a/src/cantor.kcfg
+++ b/src/cantor.kcfg
@@ -30,6 +30,22 @@
<label>Enable Numbering of Expressions by default</label>
<default>false</default>
</entry>
+ <entry name="ShowTocChaptersDefault" type="Bool">
+ <label>Show chapters in the Worksheet Structure Navigator by default</label>
+ <default>true</default>
+ </entry>
+ <entry name="ShowTocSectionsDefault" type="Bool">
+ <label>Show sections in the Worksheet Structure Navigator by default</label>
+ <default>true</default>
+ </entry>
+ <entry name="ShowTocCommandEntriesDefault" type="Bool">
+ <label>Show command entries in the Worksheet Structure Navigator by default</label>
+ <default>false</default>
+ </entry>
+ <entry name="ShowTocPlotsDefault" type="Bool">
+ <label>Show plots in the Worksheet Structure Navigator by default</label>
+ <default>false</default>
+ </entry>
<entry name="AnimationDefault" type="Bool">
<label>Animate changes in the Worksheet by default</label>
<default>true</default>
@@ -164,4 +180,3 @@
</entry>
</group>
</kcfg>
-
diff --git a/src/cantor_part.cpp b/src/cantor_part.cpp
index 720b9b87..ad3e43d9 100644
--- a/src/cantor_part.cpp
+++ b/src/cantor_part.cpp
@@ -125,15 +125,23 @@ CantorPart::CantorPart(QObject* parent, const QVariantList& args)
layout->setContentsMargins({});
m_worksheet = new Worksheet(b, centralWidget);
m_worksheetview = new WorksheetView(m_worksheet, centralWidget);
+ connect(m_worksheetview, &WorksheetView::viewRectChanged, m_worksheet, &Worksheet::updateCurrentHierarchyFromView);
+ connect(m_worksheetview, &WorksheetView::userScrollStarted, m_worksheet, &Worksheet::followHierarchyFromView);
QTimer::singleShot(0, m_worksheet, &Worksheet::handleSettingsChanges);
m_worksheetview->setEnabled(false); //disable input until the session has successfully logged in and emits the ready signal
connect(m_worksheet, &Worksheet::modified, this, static_cast<void (KParts::ReadWritePart::*)()>(&KParts::ReadWritePart::setModified));
connect(m_worksheet, &Worksheet::modified, this, &CantorPart::updateCaption);
connect(m_worksheet, &Worksheet::showHelp, this, &CantorPart::showHelp);
connect(m_worksheet, &Worksheet::loaded, this, &CantorPart::initialized);
- connect(m_worksheet, &Worksheet::hierarchyChanged, this, &CantorPart::hierarchyChanged);
- connect(m_worksheet, &Worksheet::hierarhyEntryNameChange, this, &CantorPart::hierarhyEntryNameChange);
- connect(this, &CantorPart::requestScrollToHierarchyEntry, m_worksheet, &Worksheet::requestScrollToHierarchyEntry);
+ connect(m_worksheet, &Worksheet::tocNodesChanged, this, &CantorPart::tocNodesChanged);
+ connect(m_worksheet, &Worksheet::currentTocNodeChanged, this, &CantorPart::currentTocNodeChanged);
+ connect(this, &CantorPart::requestNavigateToTocNode, m_worksheet, &Worksheet::navigateToTocNode);
+ connect(this, &CantorPart::requestRenameHierarchyEntry, m_worksheet, &Worksheet::renameHierarchyEntry);
+ connect(this, &CantorPart::requestChangeHierarchyLevel, m_worksheet, &Worksheet::changeHierarchyLevel);
+ connect(this, &CantorPart::requestDeleteHierarchyEntry, m_worksheet, &Worksheet::deleteHierarchyEntry);
+ connect(this, &CantorPart::requestRenamePlot, m_worksheet, &Worksheet::renamePlot);
+ connect(this, &CantorPart::requestDeletePlot, m_worksheet, &Worksheet::deletePlot);
+ connect(this, &CantorPart::requestTocNodeSnapshot, m_worksheet, &Worksheet::emitTocNodeSnapshot);
connect(this, &CantorPart::settingsChanges, m_worksheet, &Worksheet::handleSettingsChanges);
connect(m_worksheet, &Worksheet::requestDocumentation, this, &CantorPart::documentationRequested);
@@ -394,6 +402,7 @@ void CantorPart::setReadWrite(bool rw)
m_worksheetview->setInteractive(rw);
ReadWritePart::setReadWrite(rw);
+ Q_EMIT tocReadOnlyChanged(!rw);
}
void CantorPart::setReadOnly()
diff --git a/src/cantor_part.h b/src/cantor_part.h
index 33341f30..3076ecb1 100644
--- a/src/cantor_part.h
+++ b/src/cantor_part.h
@@ -8,6 +8,7 @@
#include <QPointer>
#include <QRegularExpression>
+#include <QVariantList>
#include <QVector>
#include <KParts/ReadWritePart>
@@ -67,11 +68,18 @@ public:
Q_SIGNALS:
void setCaption(const QString& caption, const QIcon& icon);
void showHelp(const QString&);
- void hierarchyChanged(QStringList, QStringList, QList<int>);
- void hierarhyEntryNameChange(QString name, QString searchName, int depth);
+ void tocNodesChanged(QVariantList nodes);
+ void currentTocNodeChanged(QString nodeId);
void worksheetSave(const QUrl&);
void setBackendName(const QString&);
- void requestScrollToHierarchyEntry(QString);
+ void requestRenameHierarchyEntry(QString hierarchyId, QString newName);
+ void requestNavigateToTocNode(QString nodeId);
+ void requestChangeHierarchyLevel(QString hierarchyId, int levelDelta);
+ void requestDeleteHierarchyEntry(QString hierarchyId, bool deleteContents);
+ void requestRenamePlot(QString commandId, QString resultId, QString newTitle);
+ void requestDeletePlot(QString commandId, QString resultId);
+ void tocReadOnlyChanged(bool readOnly);
+ void requestTocNodeSnapshot();
void settingsChanges();
void requestDocumentation(const QString& keyword);
diff --git a/src/settings.ui b/src/settings.ui
index 882c6f95..0f6c4fc2 100644
--- a/src/settings.ui
+++ b/src/settings.ui
@@ -24,7 +24,44 @@
</property>
</widget>
</item>
- <item row="22" column="0">
+ <item row="22" column="0" colspan="6">
+ <widget class="QGroupBox" name="tocDefaultsGroupBox">
+ <property name="title">
+ <string>Worksheet Structure Navigator:</string>
+ </property>
+ <layout class="QGridLayout" name="tocDefaultsLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QCheckBox" name="kcfg_ShowTocChaptersDefault">
+ <property name="text">
+ <string>Show chapters by default</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QCheckBox" name="kcfg_ShowTocSectionsDefault">
+ <property name="text">
+ <string>Show sections by default</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QCheckBox" name="kcfg_ShowTocCommandEntriesDefault">
+ <property name="text">
+ <string>Show command entries by default</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QCheckBox" name="kcfg_ShowTocPlotsDefault">
+ <property name="text">
+ <string>Show plots by default</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="23" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>