HAL
new_project_dialog.cpp
Go to the documentation of this file.
2 
6 
7 #include <QCheckBox>
8 #include <QComboBox>
9 #include <QDebug>
10 #include <QDialogButtonBox>
11 #include <QDir>
12 #include <QFile>
13 #include <QFileDialog>
14 #include <QFileInfo>
15 #include <QGridLayout>
16 #include <QLabel>
17 #include <QLineEdit>
18 #include <QPushButton>
19 #include <QRegularExpression>
20 #include <QSpacerItem>
21 
24 
25 namespace hal
26 {
28  {
29  QStyle* s = style();
30  s->unpolish(this);
31  s->polish(this);
32  QString suggestedGateLibraryPath;
33  QString suggestedGateLibraryName;
34 
35  int suggestedProjectCount = 0;
36  do
37  {
38  ++suggestedProjectCount;
39  mProjectdir = QDir::current().absoluteFilePath(QString("hal_project_%1").arg(suggestedProjectCount));
40  } while (QFileInfo(mProjectdir).exists());
41 
42  int irow = 0;
43  QGridLayout* layout = new QGridLayout(this);
44  setWindowTitle("Netlist Import");
45  layout->addWidget(new QLabel("Create new empty HAL project:", this), irow++, 0, Qt::AlignLeft);
46  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
47  layout->setRowStretch(irow - 1, 20);
48 
49  layout->addWidget(new QLabel("Location of project directory:", this), irow++, 0, Qt::AlignLeft);
50  QFrame* frameProjectdir = new QFrame(this);
51  QHBoxLayout* layProjectdir = new QHBoxLayout(frameProjectdir);
52  mEditProjectdir = new QLineEdit(mProjectdir, frameProjectdir);
53  layProjectdir->addWidget(mEditProjectdir);
54  QPushButton* butFiledialog = new QPushButton(gui_utility::getStyledSvgIcon(mSaveIconStyle, mSaveIconPath), "", frameProjectdir);
55  connect(butFiledialog, &QPushButton::clicked, this, &NewProjectDialog::handleFileDialogTriggered);
56  layProjectdir->addWidget(butFiledialog);
58  layout->addWidget(frameProjectdir, irow++, 0);
59  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
60 
61  QLabel* labGatelib = new QLabel("Gate library:", this);
62  layout->addWidget(labGatelib, irow++, 0, Qt::AlignLeft);
63  mComboGatelib = new QComboBox(this);
65  for (const std::filesystem::path& path : gate_library_manager::get_all_path())
66  {
67  int n = mGateLibraryPath.size();
68  QString qName = QString::fromStdString(path.filename());
69  mGateLibraryMap.insert(qName, n);
70  QString qPath = QString::fromStdString(path.string());
71  mGateLibraryPath.append(qPath);
72  if (qPath == suggestedGateLibraryPath)
73  suggestedGateLibraryName = qName;
74  }
75  if (suggestedGateLibraryName.isEmpty() && !suggestedGateLibraryPath.isEmpty())
76  {
77  // suggested gate library not found in default path
78  QFileInfo info(suggestedGateLibraryPath);
79  suggestedGateLibraryName = info.fileName();
80  int n = mGateLibraryPath.size();
81  mGateLibraryMap.insert(suggestedGateLibraryName, n);
82  mGateLibraryPath.append(suggestedGateLibraryPath);
83  }
84  mComboGatelib->addItems(mGateLibraryMap.keys());
85  if (!suggestedGateLibraryName.isEmpty())
86  mComboGatelib->setCurrentText(suggestedGateLibraryName);
87 
89  layout->addWidget(mComboGatelib, irow++, 0);
90 
91  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
92  layout->setRowStretch(irow - 1, 20);
93  mCheckCopyGatelib = new QCheckBox("Copy gate library into project directory");
94  layout->addWidget(mCheckCopyGatelib, irow++, 0, Qt::AlignLeft);
95  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
96  layout->setRowStretch(irow - 1, 100);
100  layout->addWidget(dbb, irow++, 0, Qt::AlignRight);
101  mOkButton = dbb->button(QDialogButtonBox::Ok);
102  connect(mComboGatelib, &QComboBox::currentTextChanged, this, &NewProjectDialog::handleGateLibraryPathChanged);
103  handleGateLibraryPathChanged(mComboGatelib->currentText());
104  }
105 
107  {
108  return mEditProjectdir->text();
109  }
110 
111  void NewProjectDialog::handleFileDialogTriggered()
112  {
113  QString dir = QFileDialog::getSaveFileName(this, "Enter new project directory", QFileInfo(mProjectdir).path(), "", nullptr, QFileDialog::ShowDirsOnly);
114  if (dir.isEmpty())
115  return;
116  mEditProjectdir->setText(dir);
117  }
118 
119  void NewProjectDialog::handleGateLibraryPathChanged(const QString& txt)
120  {
121  if (mGateLibraryMap.value(txt, -1) < 0)
122  {
123  mCheckCopyGatelib->setCheckState(Qt::Unchecked);
124  mCheckCopyGatelib->setDisabled(true);
125  if (mOkButton)
126  mOkButton->setDisabled(true);
127  }
128  else
129  {
130  mCheckCopyGatelib->setEnabled(true);
131  if (mOkButton)
132  mOkButton->setEnabled(true);
133  }
134  }
135 
137  {
138  QString seltxt = mComboGatelib->currentText();
139  int inx = mGateLibraryMap.value(seltxt, -1);
140  if (inx < 0)
141  return QString();
142  return mGateLibraryPath.at(inx);
143  }
144 
146  {
147  return mCheckCopyGatelib->isChecked();
148  }
149 } // namespace hal
QString projectDirectory() const
NewProjectDialog(QWidget *parent=nullptr)
QString gateLibraryPath() const
std::vector< std::filesystem::path > get_all_path()
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
n
Definition: test.py:6
QLineEdit * mEditProjectdir
QComboBox * mComboGatelib
bool isChecked() const const
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setCheckState(Qt::CheckState state)
void addItem(const QString &text, const QVariant &userData)
void addItems(const QStringList &texts)
void setCurrentText(const QString &text)
void currentTextChanged(const QString &text)
virtual void accept()
virtual void reject()
QPushButton * button(QDialogButtonBox::StandardButton which) const const
QString absoluteFilePath(const QString &fileName) const const
QDir current()
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString fileName() const const
virtual void addItem(QLayoutItem *item)=0
void addWidget(QWidget *w)
void append(const T &value)
const T & at(int i) const const
int size() const const
QMap::iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
const T value(const Key &key, const T &defaultValue) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString fromStdString(const std::string &str)
bool isEmpty() const const
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
AlignLeft
Unchecked
Horizontal
void setEnabled(bool)
QLayout * layout() const const
void setDisabled(bool disable)
void setSizePolicy(QSizePolicy)
QStyle * style() const const
void setWindowTitle(const QString &)