Showing with 70 additions and 28 deletions.
  1. +18 −2 devel-docs/BugsAndFeatures
  2. +50 −26 src/libkstapp/commandlineparser.cpp
  3. +2 −0 src/libkstapp/commandlineparser.h
20 changes: 18 additions & 2 deletions devel-docs/BugsAndFeatures
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
kst seems to crash with zero sized data files.
White border around plot for black themes shouldn't be there.

------------
-------------

Equations could allow matrixes
- Treated like vectors
- size of output matrix based on input matrix size.
- Issue: how to treat inconsistent sized things

-----------

Should error out with no valid curves/matrixes displayed for non-empty command line?
or specifying a file/limits should instead set defaults for wizard, etc?

-------------

Icons are very small by default in UHD ubuntu 20.04

--------------

Save a kst session. File dialog recent files doesn't include ".kst" if it was
automatically added on save.
Expand Down
76 changes: 50 additions & 26 deletions src/libkstapp/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ namespace Kst {
" -d: Use points for the next curve.\n"
" -l: Use lines for the next curve.\n"
" -b: Use bargraph for the next curve.\n"
" --xlabel <X Label> Set X label of all future plots.\n"
" --ylabel <Y Label> Set Y label of all future plots.\n"
" --xlabelauto AutoSet X label of all future plots.\n"
" --ylabelauto AutoSet Y label of all future plots.\n"
" --xlabel <X Label> Set X label of all subsequent plots.\n"
" --ylabel <Y Label> Set Y label of all subsequent plots.\n"
" --xlabelauto AutoSet X label of all subsequent plots.\n"
" --ylabelauto AutoSet Y label of all subsequent plots.\n"
" --showLegend Show legends for all subsequent plots."
" --hideLegend Hide legends for all subsequent plots."
" --autoLegend Auto legends for all subsequent plots."
"Data Object Modifiers\n"
" -x <field>: Create vector and use as X vector for curves.\n"
" -e <field>: Create vector and use as Y-error vector for next -y.\n"
Expand Down Expand Up @@ -169,6 +172,7 @@ CommandLineParser::CommandLineParser(Document *doc, MainWindow* mw) :
_numFrames(-1), _startFrame(-1),
_skip(0), _plotName(), _errorField(), _fileName(), _xField(QString("INDEX")),
_pngFile(QString()), _pngWidth(-1), _pngHeight(-1), _printFile(QString()), _landscape(false), _plotItem(0),
_legendMode(2),
_num_cols(0), _asciiFirstLine(-1), _asciiFieldLine(-1), _asciiNoFieldNames(false),
_asciiUnitsLine(-1), _asciiNoUnits(false), _asciiSpaceDelim(false),
_asciiDelim('\0'), _asciiFixedWidth(-1), _asciiNoFixedWidth(false),
Expand Down Expand Up @@ -252,7 +256,10 @@ DataVectorPtr CommandLineParser::createOrFindDataVector(QString field, DataSourc
if (ds->fileType() == "ASCII file") {
QRegExp num("^[0-9]{1,2}$");
if (num.exactMatch(field)) {
field = ds->vector().list()[field.toInt()];
int field_num = field.toInt();
if (field_num < ds->vector().list().size()) {
field = ds->vector().list()[field.toInt()];
}
}
}
// check to see if an identical vector already exists. If so, use it.
Expand Down Expand Up @@ -330,8 +337,14 @@ void CommandLineParser::addCurve(CurvePtr curve)
}
PlotRenderItem *renderItem = _plotItem->renderItem(PlotRenderItem::Cartesian);
renderItem->addRelation(kst_cast<Relation>(curve));
if (renderItem->relationList().size()>1) {
if (_legendMode == 2 ) { // auto legened
if (renderItem->relationList().size()>1) {
_plotItem->setShowLegend(true,true);
}
} else if (_legendMode == 1) {
_plotItem->setShowLegend(true,true);
} else {
_plotItem->setShowLegend(false, false);
}
_plotItem->update();
}
Expand Down Expand Up @@ -429,6 +442,21 @@ QString CommandLineParser::kstFileName() {
}
}

bool CommandLineParser::checkFile(QString filename) {
QFileInfo info(filename);
if (!info.exists()) {
printUsage(tr("file %1 does not exist.\n").arg(filename));
return false;
}
if (info.isFile()) {
if (info.size() == 0) {
printUsage(tr("file %1 is empty.\n").arg(filename));
return false;
}
}
return true;
}

bool CommandLineParser::processCommandLine(bool *ok) {
QString arg, param;
*ok=true;
Expand Down Expand Up @@ -517,10 +545,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
*ok = _setStringArg(_xField,tr("Usage: -x <xfieldname>\n"));
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand All @@ -544,10 +570,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
}
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -598,10 +622,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
if (*ok) {
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -640,17 +662,21 @@ bool CommandLineParser::processCommandLine(bool *ok) {
_xlabel.clear();
} else if (arg == "--ylabelauto") {
_ylabel.clear();
} else if (arg == "--showLegend") {
_legendMode = 1;
} else if (arg == "--hideLegend") {
_legendMode = 0;
} else if (arg == "--autoLegend") {
_legendMode = 2;
} else if (arg == "-h") {
QString field;
*ok = _setStringArg(field,tr("Usage: -h <fieldname>\n"));

if (*ok) {
for ( int i_file=0; i_file<_fileNames.size(); i_file++ ) {
QString file = _fileNames.at ( i_file );
QFileInfo info ( file );
if ( !info.exists() || !info.isFile() ) {
printUsage ( tr ( "file %1 does not exist\n" ).arg ( file ) );
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down Expand Up @@ -687,10 +713,8 @@ bool CommandLineParser::processCommandLine(bool *ok) {
if (*ok) {
for (int i_file=0; i_file<_fileNames.size(); i_file++) {
QString file = _fileNames.at(i_file);
QFileInfo info(file);
if (!info.exists() || !info.isFile()) {
printUsage(tr("file %1 does not exist\n").arg(file));
*ok = false;
*ok = checkFile(file);
if (*ok == false) {
break;
}

Expand Down
2 changes: 2 additions & 0 deletions src/libkstapp/commandlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CommandLineParser:QObject
~CommandLineParser();

bool processCommandLine(bool *ok);
bool checkFile(QString filename);
QString kstFileName();
QString pngFile() const {return _pngFile;}
int pngWidth() const {return _pngWidth;}
Expand Down Expand Up @@ -73,6 +74,7 @@ class CommandLineParser:QObject
PlotItem *_plotItem;
QString _xlabel;
QString _ylabel;
int _legendMode;

// lists of command line named plot items (and their names).
QList<PlotItem*> _plotItems;
Expand Down