From 971c2cb9521956501a4ebe9697ab1a65a16e5185 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 7 Apr 2011 15:43:11 +0000 Subject: [PATCH] Add Qt version of stderr for messages; fix non-Windows code to use installed attribute data file; clean up code --- cmd/gvedit/csettings.cpp | 26 +++++++++++++++----------- cmd/gvedit/main.cpp | 13 ++++++++----- cmd/gvedit/mainwindow.h | 3 +++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/cmd/gvedit/csettings.cpp b/cmd/gvedit/csettings.cpp index 919df3e6a..41f5174fb 100644 --- a/cmd/gvedit/csettings.cpp +++ b/cmd/gvedit/csettings.cpp @@ -23,9 +23,6 @@ #include "mainwindow.h" #include - - - #define WIDGET(t,f) ((t*)findChild(#f)) typedef struct { const char* data; @@ -64,12 +61,13 @@ bool loadAttrs(const QString fileName,QComboBox* cbNameG,QComboBox* cbNameN,QCom } file.close(); } - return false; - - - + else { + errout << "Could not open attribute name file \"" << fileName << "\" for reading\n" << flush; + } + return false; } + QString stripFileExtension(QString fileName) { int idx; @@ -108,11 +106,13 @@ char* graph_reader( char * str, int num, FILE * stream ) //helper function to lo CFrmSettings::CFrmSettings() { - this->gvc=gvContext(); + this->gvc = gvContext(); Ui_Dialog tempDia; tempDia.setupUi(this); - graph=NULL; - + graph = NULL; +#ifndef WIN32 + QString pfx (GVEDIT_DATADIR); +#endif connect(WIDGET(QPushButton,pbAdd),SIGNAL(clicked()),this,SLOT(addSlot())); connect(WIDGET(QPushButton,pbNew),SIGNAL(clicked()),this,SLOT(newSlot())); @@ -127,13 +127,17 @@ CFrmSettings::CFrmSettings() scopeChangedSlot(0); +#ifdef WIN32 loadAttrs("./attrs.txt",WIDGET(QComboBox,cbNameG),WIDGET(QComboBox,cbNameN),WIDGET(QComboBox,cbNameE)); +#else + loadAttrs(pfx + "/attrs.txt",WIDGET(QComboBox,cbNameG),WIDGET(QComboBox,cbNameN),WIDGET(QComboBox,cbNameE)); +#endif setWindowIcon(QIcon(":/images/icon.png")); } void CFrmSettings::outputSlot() { - QString _filter="Output File(*."+WIDGET(QComboBox,cbExtension)->currentText()+")"; + QString _filter = "Output File(*."+WIDGET(QComboBox,cbExtension)->currentText()+")"; QString fileName = QFileDialog::getSaveFileName(this, tr("Save Graph As.."),"/",_filter); if (!fileName.isEmpty()) WIDGET(QLineEdit,leOutput)->setText(fileName); diff --git a/cmd/gvedit/main.cpp b/cmd/gvedit/main.cpp index a59c94808..9678442a5 100644 --- a/cmd/gvedit/main.cpp +++ b/cmd/gvedit/main.cpp @@ -20,6 +20,8 @@ #endif #include #include +#include +/* #include */ #include "mainwindow.h" #ifdef HAVE_GETOPT_H @@ -52,6 +54,8 @@ static char* cmd; extern int Verbose; +QTextStream errout (stderr, QIODevice::WriteOnly); + static char *useString = "Usage: gvedit [-v?] \n\ -v - verbose\n\ @@ -77,9 +81,7 @@ static char **parseArgs(int argc, char *argv[]) if (optopt == '?') usage(0); else - fprintf(stderr, - "%s : option -%c unrecognized - ignored\n", - cmd, optopt); + errout << cmd << " : option -" << ((char)optopt) << " unrecognized - ignored\n" << flush; break; } } @@ -95,8 +97,8 @@ static char **parseArgs(int argc, char *argv[]) int main(int argc, char *argv[]) { - Q_INIT_RESOURCE(mdi); + int ret; QApplication app(argc, argv); char** files = parseArgs (argc, argv); @@ -107,5 +109,6 @@ int main(int argc, char *argv[]) files++; } mainWin.show(); - return app.exec(); + ret = app.exec(); + return ret; } diff --git a/cmd/gvedit/mainwindow.h b/cmd/gvedit/mainwindow.h index c20279037..73847b056 100644 --- a/cmd/gvedit/mainwindow.h +++ b/cmd/gvedit/mainwindow.h @@ -20,8 +20,11 @@ These examples are published under the terms of the BSD #define CMAINWINDOW_H #include +#include #include "ui_settings.h" +extern QTextStream errout; + class MdiChild; class CFrmSettings; QT_BEGIN_NAMESPACE -- 2.40.0