use platform abstractions from Qt library
This commit is contained in:
@ -2,8 +2,6 @@ LAMMPS-GUI TODO list:
|
||||
|
||||
# Short term goals
|
||||
|
||||
- use qgetenv, qputenv for portability
|
||||
- use QFile/QDir/QFileInto for portable file and directory operations.
|
||||
- write LAMMPS GUI Howto showing/explaining options -> simplify docs and readme
|
||||
- rewrite syntax highlighting to be line oriented instead of word oriented.
|
||||
handle first part of line based on regular expressions, then advance and only highlight strings and numbers.
|
||||
|
||||
@ -170,7 +170,7 @@ void ImageViewer::createImage()
|
||||
{
|
||||
QSettings settings;
|
||||
QString dumpcmd = QString("write_dump ") + group + " image ";
|
||||
QDir dumpdir = settings.value("tempdir").toString();
|
||||
QDir dumpdir(QDir::tempPath());
|
||||
QFile dumpfile(dumpdir.absoluteFilePath(filename + ".ppm"));
|
||||
dumpcmd += dumpfile.fileName();
|
||||
|
||||
|
||||
@ -55,6 +55,7 @@ private slots:
|
||||
|
||||
public:
|
||||
void createImage();
|
||||
|
||||
private:
|
||||
void createActions();
|
||||
void updateActions();
|
||||
|
||||
@ -48,12 +48,6 @@
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static const QString blank(" ");
|
||||
static constexpr int MAXRECENT = 5;
|
||||
|
||||
@ -114,35 +108,14 @@ LammpsGui::LammpsGui(QWidget *parent, const char *filename) :
|
||||
#if defined(_OPENMP)
|
||||
// use maximum number of available threads unless OMP_NUM_THREADS was set
|
||||
int nthreads = settings.value("nthreads", omp_get_max_threads()).toInt();
|
||||
#if _WIN32
|
||||
if (!getenv("OMP_NUM_THREADS")) {
|
||||
_putenv_s("OMP_NUM_THREADS", std::to_string(nthreads).c_str());
|
||||
if (!qEnvironmentVariableIsSet("OMP_NUM_THREADS")) {
|
||||
qputenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str());
|
||||
}
|
||||
#else
|
||||
setenv("OMP_NUM_THREADS", std::to_string(nthreads).c_str(), 0);
|
||||
#endif
|
||||
#else
|
||||
int nthreads = settings.value("nthreads", 1).toInt();
|
||||
#endif
|
||||
settings.setValue("nthreads", QString::number(nthreads));
|
||||
|
||||
const char *tmpdir = getenv("TMPDIR");
|
||||
if (!tmpdir) tmpdir = getenv("TMP");
|
||||
if (!tmpdir) tmpdir = getenv("TEMPDIR");
|
||||
if (!tmpdir) tmpdir = getenv("TEMP");
|
||||
#if _WIN32
|
||||
if (!tmpdir) tmpdir = "C:\\Windows\\Temp";
|
||||
#else
|
||||
if (!tmpdir) tmpdir = "/tmp";
|
||||
#endif
|
||||
|
||||
QFileInfo newtmp(settings.value("tempdir", QString(tmpdir)).toString());
|
||||
if (newtmp.isDir() && newtmp.isWritable()) {
|
||||
settings.setValue("tempdir", newtmp.filePath());
|
||||
} else {
|
||||
settings.setValue("tempdir", QString(tmpdir));
|
||||
}
|
||||
|
||||
lammps_args.clear();
|
||||
lammps_args.push_back(mystrdup("LAMMPS-GUI"));
|
||||
lammps_args.push_back(mystrdup("-log"));
|
||||
@ -666,12 +639,8 @@ void LammpsGui::run_buffer()
|
||||
logwindow->setWindowTitle("LAMMPS-GUI - Output from running LAMMPS on buffer - " +
|
||||
current_file);
|
||||
logwindow->setWindowIcon(QIcon(":/lammps-icon-128x128.png"));
|
||||
#if (__APPLE__)
|
||||
QFont text_font("Menlo");
|
||||
#else
|
||||
QFont text_font(":/Monospace.ttf");
|
||||
#endif
|
||||
text_font.setStyleHint(QFont::TypeWriter);
|
||||
QFont text_font;
|
||||
text_font.fromString(settings.value("textfont", text_font.toString()).toString());
|
||||
logwindow->document()->setDefaultFont(text_font);
|
||||
logwindow->setLineWrapMode(LogWindow::NoWrap);
|
||||
logwindow->setMinimumSize(400, 300);
|
||||
|
||||
@ -99,11 +99,6 @@ void Preferences::accept()
|
||||
if (field)
|
||||
if (field->hasAcceptableInput()) settings->setValue("nthreads", field->text());
|
||||
|
||||
// store temp dir
|
||||
field = tabWidget->findChild<QLineEdit *>("tmpedit");
|
||||
if (field)
|
||||
if (field->hasAcceptableInput()) settings->setValue("tempdir", field->text());
|
||||
|
||||
// store image width, height, zoom, and rendering settings
|
||||
|
||||
settings->beginGroup("snapshot");
|
||||
@ -173,17 +168,6 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
||||
pltr->setObjectName("chartreplace");
|
||||
pltr->setCheckState(settings->value("chartreplace", false).toBool() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
#if !defined(__APPLE__)
|
||||
auto *tmplabel = new QLabel("Scratch Folder:");
|
||||
auto *tmpedit = new QLineEdit(settings->value("tempdir", ".").toString());
|
||||
auto *tmpbrowse = new QPushButton("Browse...");
|
||||
auto *tmplayout = new QHBoxLayout;
|
||||
tmpedit->setObjectName("tmpedit");
|
||||
tmplayout->addWidget(tmplabel);
|
||||
tmplayout->addWidget(tmpedit);
|
||||
tmplayout->addWidget(tmpbrowse);
|
||||
connect(tmpbrowse, &QPushButton::released, this, &GeneralTab::newtmpfolder);
|
||||
#endif
|
||||
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
auto *pluginlabel = new QLabel("Path to LAMMPS Shared Library File:");
|
||||
@ -213,9 +197,6 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
|
||||
layout->addWidget(logr);
|
||||
layout->addWidget(pltr);
|
||||
layout->addWidget(imgr);
|
||||
#if !defined(__APPLE__)
|
||||
layout->addLayout(tmplayout);
|
||||
#endif
|
||||
#if defined(LAMMPS_GUI_USE_PLUGIN)
|
||||
layout->addWidget(pluginlabel);
|
||||
layout->addLayout(pluginlayout);
|
||||
@ -263,18 +244,6 @@ void GeneralTab::newtextfont()
|
||||
settings.setValue("textfont", font.toString());
|
||||
}
|
||||
|
||||
void GeneralTab::newtmpfolder()
|
||||
{
|
||||
QLineEdit *field = findChild<QLineEdit *>("tmpedit");
|
||||
QString tmpdir =
|
||||
QFileDialog::getExistingDirectory(this, "Find Folder for Temporary Files", field->text());
|
||||
|
||||
if (!tmpdir.isEmpty()) {
|
||||
QFileInfo newtmp(tmpdir);
|
||||
if (newtmp.isDir() && newtmp.isWritable()) field->setText(tmpdir);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralTab::pluginpath()
|
||||
{
|
||||
QLineEdit *field = findChild<QLineEdit *>("pluginedit");
|
||||
|
||||
@ -49,7 +49,6 @@ public:
|
||||
|
||||
private slots:
|
||||
void pluginpath();
|
||||
void newtmpfolder();
|
||||
void newallfont();
|
||||
void newtextfont();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user