From 8e54ac15421be441ece2a85ff0d61e850a99b2e9 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 13 Jul 2018 09:14:48 +0200 Subject: Use command line parameters settings for GUI as well. --- gui/basewindow.cc | 3 ++- gui/basewindow.h | 6 +++--- gui/ecp5/mainwindow.cc | 3 ++- gui/ecp5/mainwindow.h | 2 +- gui/generic/mainwindow.cc | 3 ++- gui/generic/mainwindow.h | 2 +- gui/ice40/mainwindow.cc | 49 +++++++++++++++++++++++++++++------------------ gui/ice40/mainwindow.h | 6 ++++-- gui/infotab.h | 3 ++- 9 files changed, 47 insertions(+), 30 deletions(-) (limited to 'gui') diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 5a53e9cf..6bc56c7b 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -36,7 +36,8 @@ static void initBasenameResource() { Q_INIT_RESOURCE(base); } NEXTPNR_NAMESPACE_BEGIN -BaseMainWindow::BaseMainWindow(QWidget *parent) : QMainWindow(parent), ctx(nullptr) +BaseMainWindow::BaseMainWindow(std::unique_ptr context, QWidget *parent) + : QMainWindow(parent), ctx(std::move(context)) { initBasenameResource(); qRegisterMetaType(); diff --git a/gui/basewindow.h b/gui/basewindow.h index ef3dcb95..d2d0505d 100644 --- a/gui/basewindow.h +++ b/gui/basewindow.h @@ -40,9 +40,9 @@ class BaseMainWindow : public QMainWindow Q_OBJECT public: - explicit BaseMainWindow(QWidget *parent = 0); + explicit BaseMainWindow(std::unique_ptr context, QWidget *parent = 0); virtual ~BaseMainWindow(); - Context *getContext() { return ctx; } + Context *getContext() { return ctx.get(); } protected: void createMenusAndBars(); @@ -59,7 +59,7 @@ class BaseMainWindow : public QMainWindow void updateTreeView(); protected: - Context *ctx; + std::unique_ptr ctx; QTabWidget *tabWidget; QTabWidget *centralTabWidget; InfoTab *info; diff --git a/gui/ecp5/mainwindow.cc b/gui/ecp5/mainwindow.cc index 6cc3dd15..1168a55c 100644 --- a/gui/ecp5/mainwindow.cc +++ b/gui/ecp5/mainwindow.cc @@ -23,7 +23,7 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } NEXTPNR_NAMESPACE_BEGIN -MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent) +MainWindow::MainWindow(std::unique_ptr context, QWidget *parent) : BaseMainWindow(std::move(context), parent) { initMainResource(); @@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent) setWindowTitle(title.c_str()); createMenu(); + Q_EMIT contextChanged(ctx.get()); } MainWindow::~MainWindow() {} diff --git a/gui/ecp5/mainwindow.h b/gui/ecp5/mainwindow.h index fd9812cd..e97bb4e7 100644 --- a/gui/ecp5/mainwindow.h +++ b/gui/ecp5/mainwindow.h @@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(std::unique_ptr context, QWidget *parent = 0); virtual ~MainWindow(); public: diff --git a/gui/generic/mainwindow.cc b/gui/generic/mainwindow.cc index fef63094..88e291e6 100644 --- a/gui/generic/mainwindow.cc +++ b/gui/generic/mainwindow.cc @@ -23,7 +23,7 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } NEXTPNR_NAMESPACE_BEGIN -MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent) +MainWindow::MainWindow(std::unique_ptr context, QWidget *parent) : BaseMainWindow(std::move(context), parent) { initMainResource(); @@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent) setWindowTitle(title.c_str()); createMenu(); + Q_EMIT contextChanged(ctx.get()); } MainWindow::~MainWindow() {} diff --git a/gui/generic/mainwindow.h b/gui/generic/mainwindow.h index fd9812cd..e97bb4e7 100644 --- a/gui/generic/mainwindow.h +++ b/gui/generic/mainwindow.h @@ -29,7 +29,7 @@ class MainWindow : public BaseMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(std::unique_ptr context, QWidget *parent = 0); virtual ~MainWindow(); public: diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 6f0a9b97..e8476fcf 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -34,7 +34,8 @@ static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } NEXTPNR_NAMESPACE_BEGIN -MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent), timing_driven(false) +MainWindow::MainWindow(std::unique_ptr context, QWidget *parent) + : BaseMainWindow(std::move(context), parent), timing_driven(false) { initMainResource(); @@ -60,6 +61,8 @@ MainWindow::MainWindow(QWidget *parent) : BaseMainWindow(parent), timing_driven( connect(this, SIGNAL(contextChanged(Context *)), task, SIGNAL(contextChanged(Context *))); createMenu(); + + Q_EMIT contextChanged(ctx.get()); } MainWindow::~MainWindow() { delete task; } @@ -75,7 +78,7 @@ void MainWindow::createMenu() actionLoadJSON->setIcon(iconLoadJSON); actionLoadJSON->setStatusTip("Open an existing JSON file"); connect(actionLoadJSON, SIGNAL(triggered()), this, SLOT(open_json())); - actionLoadJSON->setEnabled(false); + actionLoadJSON->setEnabled(true); actionLoadPCF = new QAction("Open PCF", this); QIcon iconLoadPCF; @@ -239,22 +242,36 @@ void MainWindow::new_proj() if (ok && !item.isEmpty()) { disableActions(); + preload_pcf = ""; chipArgs.package = package.toStdString().c_str(); - if (ctx) - delete ctx; - ctx = new Context(chipArgs); - - Q_EMIT contextChanged(ctx); + ctx = std::unique_ptr(new Context(chipArgs)); - actionLoadJSON->setEnabled(true); + Q_EMIT contextChanged(ctx.get()); } } } +void MainWindow::load_json(std::string filename, std::string pcf) +{ + tabWidget->setCurrentWidget(info); + preload_pcf = pcf; + disableActions(); + Q_EMIT task->loadfile(filename); +} + +void MainWindow::load_pcf(std::string filename) +{ + tabWidget->setCurrentWidget(info); + + disableActions(); + Q_EMIT task->loadpcf(filename); +} + void MainWindow::newContext(Context *ctx) { std::string title = "nextpnr-ice40 - " + ctx->getChipName() + " ( " + chipArgs.package + " )"; setWindowTitle(title.c_str()); + info->clearBuffer(); } void MainWindow::open_proj() @@ -272,12 +289,7 @@ void MainWindow::open_json() { QString fileName = QFileDialog::getOpenFileName(this, QString("Open JSON"), QString(), QString("*.json")); if (!fileName.isEmpty()) { - tabWidget->setCurrentWidget(info); - - std::string fn = fileName.toStdString(); - disableActions(); - timing_driven = false; - Q_EMIT task->loadfile(fn); + load_json(fileName.toStdString(), ""); } } @@ -285,11 +297,7 @@ void MainWindow::open_pcf() { QString fileName = QFileDialog::getOpenFileName(this, QString("Open PCF"), QString(), QString("*.pcf")); if (!fileName.isEmpty()) { - tabWidget->setCurrentWidget(info); - - std::string fn = fileName.toStdString(); - disableActions(); - Q_EMIT task->loadpcf(fn); + load_pcf(fileName.toStdString()); } } @@ -330,9 +338,12 @@ void MainWindow::loadfile_finished(bool status) log("Loading design successful.\n"); actionLoadPCF->setEnabled(true); actionPack->setEnabled(true); + if (!preload_pcf.empty()) + load_pcf(preload_pcf); Q_EMIT updateTreeView(); } else { log("Loading design failed.\n"); + preload_pcf = ""; } } diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index 8e847adc..2bed925f 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -30,12 +30,13 @@ class MainWindow : public BaseMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(std::unique_ptr context, QWidget *parent = 0); virtual ~MainWindow(); public: void createMenu(); - + void load_json(std::string filename, std::string pcf); + void load_pcf(std::string filename); protected Q_SLOTS: virtual void new_proj(); virtual void open_proj(); @@ -78,6 +79,7 @@ class MainWindow : public BaseMainWindow bool timing_driven; ArchArgs chipArgs; + std::string preload_pcf; }; NEXTPNR_NAMESPACE_END diff --git a/gui/infotab.h b/gui/infotab.h index 0116755e..41529973 100644 --- a/gui/infotab.h +++ b/gui/infotab.h @@ -33,9 +33,10 @@ class InfoTab : public QWidget public: explicit InfoTab(QWidget *parent = 0); void info(std::string str); + public Q_SLOTS: + void clearBuffer(); private Q_SLOTS: void showContextMenu(const QPoint &pt); - void clearBuffer(); private: QPlainTextEdit *plainTextEdit; -- cgit v1.2.3