diff options
-rw-r--r-- | gui/mainwindow.cc | 312 | ||||
-rw-r--r-- | gui/mainwindow.h | 10 |
2 files changed, 145 insertions, 177 deletions
diff --git a/gui/mainwindow.cc b/gui/mainwindow.cc index b2195b2f..285a9250 100644 --- a/gui/mainwindow.cc +++ b/gui/mainwindow.cc @@ -9,6 +9,76 @@ #include <QDate> #include <QLocale> +enum class ElementType +{ + BEL, + WIRE, + PIP +}; + +class ElementTreeItem : public QTreeWidgetItem +{ + public: + ElementTreeItem(ElementType t, QString str) + : QTreeWidgetItem((QTreeWidget *)nullptr, QStringList(str)), type(t) + { + } + virtual ~ElementTreeItem(){}; + + ElementType getType() { return type; }; + + private: + ElementType type; +}; + +class BelTreeItem : public ElementTreeItem +{ + public: + BelTreeItem(IdString d, ElementType type, QString str) + : ElementTreeItem(type, str) + { + this->data = d; + } + virtual ~BelTreeItem(){}; + + IdString getData() { return this->data; }; + + private: + IdString data; +}; + +class WireTreeItem : public ElementTreeItem +{ + public: + WireTreeItem(IdString d, ElementType type, QString str) + : ElementTreeItem(type, str) + { + this->data = d; + } + virtual ~WireTreeItem(){}; + + IdString getData() { return this->data; }; + + private: + IdString data; +}; + +class PipTreeItem : public ElementTreeItem +{ + public: + PipTreeItem(IdString d, ElementType type, QString str) + : ElementTreeItem(type, str) + { + this->data = d; + } + virtual ~PipTreeItem(){}; + + IdString getData() { return this->data; }; + + private: + IdString data; +}; + MainWindow::MainWindow(Design *_design, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), design(_design) { @@ -25,8 +95,8 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) QList<QTreeWidgetItem *> bel_items; for (auto bel : design->chip.getBels()) { auto name = design->chip.getBelName(bel); - bel_items.append(new QTreeWidgetItem( - (QTreeWidget *)nullptr, QStringList(QString(name.c_str())))); + bel_items.append( + new BelTreeItem(name, ElementType::BEL, QString(name.c_str()))); } bel_root->addChildren(bel_items); @@ -36,8 +106,8 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) ui->treeWidget->insertTopLevelItem(0, wire_root); for (auto wire : design->chip.getWires()) { auto name = design->chip.getWireName(wire); - wire_items.append(new QTreeWidgetItem( - (QTreeWidget *)nullptr, QStringList(QString(name.c_str())))); + wire_items.append(new WireTreeItem(name, ElementType::WIRE, + QString(name.c_str()))); } wire_root->addChildren(wire_items); @@ -47,8 +117,8 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) ui->treeWidget->insertTopLevelItem(0, pip_root); for (auto pip : design->chip.getPips()) { auto name = design->chip.getPipName(pip); - pip_items.append(new QTreeWidgetItem( - (QTreeWidget *)nullptr, QStringList(QString(name.c_str())))); + pip_items.append( + new PipTreeItem(name, ElementType::PIP, QString(name.c_str()))); } pip_root->addChildren(pip_items); @@ -65,191 +135,82 @@ MainWindow::MainWindow(Design *_design, QWidget *parent) variantManager = new QtVariantPropertyManager(); - int i = 0; - QtProperty *topItem = variantManager->addProperty( - QtVariantPropertyManager::groupTypeId(), - QString::number(i++) + QLatin1String(" Group Property")); - - QtVariantProperty *item = variantManager->addProperty( - QVariant::Bool, - QString::number(i++) + QLatin1String(" Bool Property")); - item->setValue(true); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Int, - QString::number(i++) + - QLatin1String(" Int Property")); - item->setValue(20); - item->setAttribute(QLatin1String("minimum"), 0); - item->setAttribute(QLatin1String("maximum"), 100); - item->setAttribute(QLatin1String("singleStep"), 10); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::Double, - QString::number(i++) + QLatin1String(" Double Property")); - item->setValue(1.2345); - item->setAttribute(QLatin1String("singleStep"), 0.1); - item->setAttribute(QLatin1String("decimals"), 3); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::String, - QString::number(i++) + QLatin1String(" String Property")); - item->setValue("Value"); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Date, - QString::number(i++) + - QLatin1String(" Date Property")); - item->setValue(QDate::currentDate().addDays(2)); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Time, - QString::number(i++) + - QLatin1String(" Time Property")); - item->setValue(QTime::currentTime()); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::DateTime, - QString::number(i++) + QLatin1String(" DateTime Property")); - item->setValue(QDateTime::currentDateTime()); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::KeySequence, - QString::number(i++) + QLatin1String(" KeySequence Property")); - item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q)); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Char, - QString::number(i++) + - QLatin1String(" Char Property")); - item->setValue(QChar(386)); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::Locale, - QString::number(i++) + QLatin1String(" Locale Property")); - item->setValue(QLocale(QLocale::Polish, QLocale::Poland)); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::Point, - QString::number(i++) + QLatin1String(" Point Property")); - item->setValue(QPoint(10, 10)); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::PointF, - QString::number(i++) + QLatin1String(" PointF Property")); - item->setValue(QPointF(1.2345, -1.23451)); - item->setAttribute(QLatin1String("decimals"), 3); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Size, - QString::number(i++) + - QLatin1String(" Size Property")); - item->setValue(QSize(20, 20)); - item->setAttribute(QLatin1String("minimum"), QSize(10, 10)); - item->setAttribute(QLatin1String("maximum"), QSize(30, 30)); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::SizeF, - QString::number(i++) + QLatin1String(" SizeF Property")); - item->setValue(QSizeF(1.2345, 1.2345)); - item->setAttribute(QLatin1String("decimals"), 3); - item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34)); - item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78)); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Rect, - QString::number(i++) + - QLatin1String(" Rect Property")); - item->setValue(QRect(10, 10, 20, 20)); - topItem->addSubProperty(item); - item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50)); - - item = variantManager->addProperty( - QVariant::RectF, - QString::number(i++) + QLatin1String(" RectF Property")); - item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345)); - topItem->addSubProperty(item); - item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50)); - item->setAttribute(QLatin1String("decimals"), 3); - - item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), - QString::number(i++) + - QLatin1String(" Enum Property")); - QStringList enumNames; - enumNames << "Enum0" - << "Enum1" - << "Enum2"; - item->setAttribute(QLatin1String("enumNames"), enumNames); - item->setValue(1); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(), - QString::number(i++) + - QLatin1String(" Flag Property")); - QStringList flagNames; - flagNames << "Flag0" - << "Flag1" - << "Flag2"; - item->setAttribute(QLatin1String("flagNames"), flagNames); - item->setValue(5); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::SizePolicy, - QString::number(i++) + QLatin1String(" SizePolicy Property")); - topItem->addSubProperty(item); - - item = variantManager->addProperty(QVariant::Font, - QString::number(i++) + - QLatin1String(" Font Property")); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::Cursor, - QString::number(i++) + QLatin1String(" Cursor Property")); - topItem->addSubProperty(item); - - item = variantManager->addProperty( - QVariant::Color, - QString::number(i++) + QLatin1String(" Color Property")); - topItem->addSubProperty(item); - variantFactory = new QtVariantEditorFactory(); - variantEditor = new QtTreePropertyBrowser(); - variantEditor->setFactoryForManager(variantManager, variantFactory); - variantEditor->addProperty(topItem); - variantEditor->setPropertiesWithoutValueMarked(true); - variantEditor->setRootIsDecorated(false); - variantEditor->show(); - ui->splitter_2->addWidget(variantEditor); + propertyEditor = new QtTreePropertyBrowser(); + propertyEditor->setFactoryForManager(variantManager, variantFactory); + propertyEditor->setPropertiesWithoutValueMarked(true); + propertyEditor->setRootIsDecorated(false); + propertyEditor->show(); + ui->splitter_2->addWidget(propertyEditor); + + connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), + SLOT(onItemClicked(QTreeWidgetItem *, int))); } MainWindow::~MainWindow() { delete variantManager; delete variantFactory; - delete variantEditor; + delete propertyEditor; delete ui; } +void MainWindow::addProperty(QtVariantProperty *property, const QString &id) +{ + propertyToId[property] = id; + idToProperty[id] = property; + QtBrowserItem *item = propertyEditor->addProperty(property); +} + +void MainWindow::onItemClicked(QTreeWidgetItem *item, int pos) +{ + if (!item->parent()) + return; + ElementType type = static_cast<ElementTreeItem *>(item)->getType(); + QMap<QtProperty *, QString>::ConstIterator itProp = + propertyToId.constBegin(); + while (itProp != propertyToId.constEnd()) { + delete itProp.key(); + itProp++; + } + propertyToId.clear(); + idToProperty.clear(); + + if (type == ElementType::BEL) { + IdString c = static_cast<BelTreeItem *>(item)->getData(); + + QtVariantProperty *topItem = + variantManager->addProperty(QVariant::String, QString("Name")); + topItem->setValue(QString(c.c_str())); + addProperty(topItem, QString("Name")); + } else if (type == ElementType::WIRE) { + IdString c = static_cast<WireTreeItem *>(item)->getData(); + + QtVariantProperty *topItem = + variantManager->addProperty(QVariant::String, QString("Name")); + topItem->setValue(QString(c.c_str())); + addProperty(topItem, QString("Name")); + + } else if (type == ElementType::PIP) { + IdString c = static_cast<PipTreeItem *>(item)->getData(); + + QtVariantProperty *topItem = + variantManager->addProperty(QVariant::String, QString("Name")); + topItem->setValue(QString(c.c_str())); + addProperty(topItem, QString("Name")); + } +} + void MainWindow::prepareMenu(const QPoint &pos) { QTreeWidget *tree = ui->treeWidget; - QTreeWidgetItem *item = tree->itemAt(pos); + itemContextMenu = tree->itemAt(pos); QAction *selectAction = new QAction("&Select", this); selectAction->setStatusTip("Select item on view"); - connect(selectAction, SIGNAL(triggered()), this, SLOT(selectObject(item))); + connect(selectAction, SIGNAL(triggered()), this, SLOT(selectObject())); QMenu menu(this); menu.addAction(selectAction); @@ -258,11 +219,12 @@ void MainWindow::prepareMenu(const QPoint &pos) menu.exec(tree->mapToGlobal(pos)); } -void MainWindow::selectObject(QTreeWidgetItem *item) +void MainWindow::selectObject() { ui->plainTextEdit->moveCursor(QTextCursor::End); ui->plainTextEdit->insertPlainText( - std::string("selected " + item->text(0).toStdString() + "\n") + std::string("selected " + itemContextMenu->text(0).toStdString() + + "\n") .c_str()); ui->plainTextEdit->moveCursor(QTextCursor::End); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 27918486..b528f6b7 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -27,11 +27,13 @@ class MainWindow : public QMainWindow private: int executePython(std::string command); + void addProperty(QtVariantProperty *property, const QString &id); private Q_SLOTS: void on_lineEdit_returnPressed(); void prepareMenu(const QPoint &pos); - void selectObject(QTreeWidgetItem *item); + void selectObject(); + void onItemClicked(QTreeWidgetItem *item, int); private: Ui::MainWindow *ui; @@ -39,7 +41,11 @@ class MainWindow : public QMainWindow Design *design; QtVariantPropertyManager *variantManager; QtVariantEditorFactory *variantFactory; - QtTreePropertyBrowser *variantEditor; + QtTreePropertyBrowser *propertyEditor; + QTreeWidgetItem *itemContextMenu; + + QMap<QtProperty *, QString> propertyToId; + QMap<QString, QtVariantProperty *> idToProperty; }; #endif // MAINWINDOW_H |