HAL
export_registered_format.cpp
Go to the documentation of this file.
2 #include <QFileDialog>
3 #include <QDir>
4 #include <QApplication>
5 #include <QFile>
6 #include <QColor>
7 #include <QFileInfo>
8 #include <QMessageBox>
9 #include "gui/gui_globals.h"
11 
12 namespace hal {
14  : mExtensions(exts), mFilename(filename)
15  {;}
16 
18  {
19  int wordcount = 0;
20  QString filter;
21  for (const QString& s : mExtensions)
22  {
23  switch(wordcount++)
24  {
25  case 0: break;
26  case 1: filter += " (*"; break;
27  default: filter += " *";
28  }
29  filter += s;
30  }
31  filter += ")";
32  QWidget* parent = qApp->activeWindow();
33 
34  for (;;) // loop if no existing file override
35  {
36  mFilename = QFileDialog::getSaveFileName(
37  parent,
38  "Export netlist",
40  filter,
41  nullptr);
42  if (mFilename.isEmpty()) return false;
43 
44  bool goodExtension = false;
45  for (int i=1; i<mExtensions.size(); i++)
46  if (mFilename.endsWith(mExtensions.at(i)))
47  {
48  goodExtension = true;
49  break;
50  }
51 
52  if (!goodExtension)
53  {
54  QFileInfo fi(mFilename);
55  mFilename = fi.path() + "/" + fi.completeBaseName() + mExtensions.last();
56 
57  if (QFileInfo(mFilename).exists())
58  {
59  if (QMessageBox::question(parent, "Export netlist",
60  mFilename + " already exists.\nDo you want to replace it?",
62  != QMessageBox::Ok) continue;
63  }
64  }
65 
66  return true;
67  }
68  }
69 
71  {
73  }
74 }
ExportRegisteredFormat(const QStringList &exts, const QString &filename=QString())
bool write(Netlist *netlist, const ProgramArguments &args)
Netlist * gNetlist
Definition: plugin_gui.cpp:80
QString currentPath()
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString completeBaseName() const const
QString path() const const
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
std::string toStdString() const const