From 0b6cbf825ac3c67e5c62de1e8c2d5fad6f2de460 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 9 Feb 2026 17:26:51 -0700 Subject: [PATCH] feat: Add feature browser dock widget with document synchronization Co-authored-by: aider (gemini/gemini-2.5-pro) --- src/Document.cpp | 2 ++ src/Document.h | 4 ++++ src/MainWindow.cpp | 34 +++++++++++++++++++++++++++++++++- src/MainWindow.h | 9 +++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Document.cpp b/src/Document.cpp index cfac37b..cf1243d 100644 --- a/src/Document.cpp +++ b/src/Document.cpp @@ -19,12 +19,14 @@ Document::~Document() void Document::addFeature(Feature* feature) { m_features.append(feature); + emit featureAdded(feature); } void Document::clear() { qDeleteAll(m_features); m_features.clear(); + emit cleared(); } bool Document::save(const QString& path) const diff --git a/src/Document.h b/src/Document.h index 2c2a023..5a7fc72 100644 --- a/src/Document.h +++ b/src/Document.h @@ -19,6 +19,10 @@ public: bool save(const QString& path) const; bool load(const QString& path); +signals: + void featureAdded(Feature* feature); + void cleared(); + private: QList m_features; }; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 4756636..cd79bb8 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -2,11 +2,15 @@ #include "ViewportWidget.h" #include "Document.h" #include "SketchFeature.h" +#include "Feature.h" #include #include #include #include +#include +#include +#include #include #include #include @@ -80,6 +84,18 @@ MainWindow::MainWindow(QWidget *parent) setCentralWidget(m_viewport); m_document = new Document(this); + connect(m_document, &Document::featureAdded, this, &MainWindow::onFeatureAdded); + connect(m_document, &Document::cleared, this, &MainWindow::onDocumentCleared); + + QDockWidget *dock = new QDockWidget("Browser", this); + addDockWidget(Qt::LeftDockWidgetArea, dock); + + m_featureTree = new QTreeWidget(dock); + m_featureTree->setHeaderHidden(true); + dock->setWidget(m_featureTree); + + m_rootItem = new QTreeWidgetItem(m_featureTree); + setCurrentFile(QString()); } @@ -161,6 +177,22 @@ void MainWindow::setCurrentFile(const QString &fileName) QString shownName = m_currentFile; if (m_currentFile.isEmpty()) - shownName = "untitled.json"; + shownName = "Untitled"; setWindowTitle(tr("%1[*] - %2").arg(QFileInfo(shownName).fileName(), tr("OpenCAD"))); + + if (m_rootItem) { + m_rootItem->setText(0, QFileInfo(shownName).fileName()); + } +} + +void MainWindow::onFeatureAdded(Feature* feature) +{ + QTreeWidgetItem *item = new QTreeWidgetItem(m_rootItem); + item->setText(0, feature->name()); + m_rootItem->setExpanded(true); +} + +void MainWindow::onDocumentCleared() +{ + qDeleteAll(m_rootItem->takeChildren()); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 897f8fa..ef0997e 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -5,6 +5,9 @@ class ViewportWidget; class Document; +class Feature; +class QTreeWidget; +class QTreeWidgetItem; class MainWindow : public QMainWindow { @@ -20,12 +23,18 @@ private slots: bool saveAs(); void createSketch(); + void onFeatureAdded(Feature* feature); + void onDocumentCleared(); + private: void setCurrentFile(const QString &fileName); ViewportWidget *m_viewport; Document *m_document; QString m_currentFile; + + QTreeWidget* m_featureTree; + QTreeWidgetItem* m_rootItem; }; #endif // MAINWINDOW_H