Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Common/SC_DirEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

*************************************************************************** */

// Written: fmckenna
// Written: fmckenna, Sina Naeimi

#include <SC_DirEdit.h>

Expand Down Expand Up @@ -64,9 +64,11 @@ SC_DirEdit::SC_DirEdit(QString theKey, bool copyFiles)
connect(chooseFile, &QPushButton::clicked, this,
[=]() {
QString fileName=QFileDialog::getExistingDirectory(this,tr("Select Directory"),"", QFileDialog::ShowDirsOnly);

theDirectory->setText(fileName);
emit dirNameChanged(fileName);

if (fileName.isEmpty() == false){
theDirectory->setText(fileName);
emit dirNameChanged(fileName);
}
});
}

Expand Down
8 changes: 4 additions & 4 deletions Common/SC_MultipleLineChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ SC_MLC_Chart::~SC_MLC_Chart()
qDebug() << "SC_MLC_Chart Destructor";
}

int
void
SC_MLC_Chart::setData(SC_MLC_ChartData *theNewData)
{
chartData = theNewData;
Expand Down Expand Up @@ -178,7 +178,7 @@ SC_MLC_Chart::setData(SC_MLC_ChartData *theNewData)
}
}

return 0;
// return 0;
}

ChartHandler:: ChartHandler(QLineSeries *theLineSeries, QGraphicsSimpleTextItem *theTextItem, QChart *theChart, QObject *parent)
Expand Down Expand Up @@ -230,7 +230,7 @@ SC_MultipleLineChart::~SC_MultipleLineChart()
}
}

int
void
SC_MultipleLineChart::setData(QMap<QString, SC_MLC_ChartData *> *newData)
{
//
Expand All @@ -257,5 +257,5 @@ SC_MultipleLineChart::setData(QMap<QString, SC_MLC_ChartData *> *newData)
theSelection->addItem(key);
}

return 0;
// return 0;
}
4 changes: 2 additions & 2 deletions Common/SC_MultipleLineChart.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SC_MLC_Chart : public QWidget {

SC_MLC_Chart(QWidget *parent = 0);
~SC_MLC_Chart();
int setData(SC_MLC_ChartData *);
void setData(SC_MLC_ChartData *);

public slots:

Expand Down Expand Up @@ -136,7 +136,7 @@ class SC_MultipleLineChart : public QWidget {
public:
SC_MultipleLineChart(QWidget *parent = 0);
~SC_MultipleLineChart();
int setData(QMap<QString, SC_MLC_ChartData *> *newData);
void setData(QMap<QString, SC_MLC_ChartData *> *newData);

public slots:

Expand Down
205 changes: 205 additions & 0 deletions Common/SC_OptionSelectionLineEdit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/* *****************************************************************************
Copyright (c) 2016-2021, The Regents of the University of California (Regents).
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS
PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

*************************************************************************** */

// Written by: Stevan Gavrilovic, Sina Naeimi

#include "SC_OptionSelectionLineEdit.h"

#include <QRegExpValidator>

#include <sstream>

SC_OptionSelectionLineEdit::SC_OptionSelectionLineEdit()
{

this->setPlaceholderText("e.g., 1, 3, 5-10, 12");

// Create a regExp validator to make sure only '-' & ',' & ' ' & numbers are input
QRegExp LERegExp ("((([0-9]*)|([0-9]+-[1-9][0-9]*))[ ]*,[ ]*)*([[0-9]+-[1-9][0-9]*|[0-9]*)");
QRegExpValidator* LEValidator = new QRegExpValidator(LERegExp);
this->setValidator(LEValidator);
}


int SC_OptionSelectionLineEdit::size()
{
return selectedComponentIDs.size();
}


void SC_OptionSelectionLineEdit::clear()
{
prevText.clear();
selectedComponentIDs.clear();
this->QLineEdit::clear();
}


void SC_OptionSelectionLineEdit::insertSelectedComponent(const int id)
{
selectedComponentIDs.insert(id);

// Reset the text on the line edit
this->setText(this->getComponentAnalysisList());
}


void SC_OptionSelectionLineEdit::insertSelectedComponents(const QVector<int>& ids)
{
for(auto&& id : ids)
selectedComponentIDs.insert(id);

// Reset the text on the line edit
this->setText(this->getComponentAnalysisList());
}


void SC_OptionSelectionLineEdit::selectComponents()
{
auto inputText = this->text();

if(inputText==prevText)
return;

selectedComponentIDs.clear();

// Quick return if the input text is empty
if(inputText.isEmpty())
return;

// Remove any white space from the string
inputText.remove(" ");

// Split the incoming text into the parts delimited by commas
std::vector<std::string> subStringVec;

// Create string stream from the string
std::stringstream s_stream(inputText.toStdString());

// Split the input string to substrings at the comma
while(s_stream.good()) {
std:: string subString;
getline(s_stream, subString, ',');

if(!subString.empty())
subStringVec.push_back(subString);
}


// Check for the case where the IDs are given as a range
std::string dashDelim = "-";

for(auto&& subStr : subStringVec)
{
// Handle the case where there is a range of assets separated by a '-'
if (subStr.find(dashDelim) != std::string::npos)
{
auto pos = subStr.find(dashDelim);
// Get the strings on either side of the '-' character
std::string intStart = subStr.substr(0, pos);
std::string intEnd = subStr.substr(pos + dashDelim.length());

// Convert them into integers
auto IDStart = std::stoi(intStart);
auto IDEnd = std::stoi(intEnd);

// Make sure that the end integer is greater than the first
if(IDStart>IDEnd)
{
QString err = "Error in the range of asset IDs provided in the Component asset selection box";
throw err;
continue;
}

// Add the IDs to the set
for(int ID = IDStart; ID<=IDEnd; ++ID)
selectedComponentIDs.insert(ID);
}
else // Asset ID is given individually
{
auto ID = std::stoi(subStr);

selectedComponentIDs.insert(ID);
}
}

// Reset the text on the line edit
auto sortedIds = this->getComponentAnalysisList();
this->setText(sortedIds);

prevText=sortedIds;

emit componentSelectionComplete();
}


std::set<int> AssetInputDelegate::getSelectedComponentIDs() const
{
return selectedComponentIDs;
}


QString AssetInputDelegate::getComponentAnalysisList()
{
QString stringList;

std::set<int>::iterator it;
for (it = selectedComponentIDs.begin(); it != selectedComponentIDs.end(); ++it)
{
int first = *it;
int next = *it;
while(std::next(it, 1) != selectedComponentIDs.end() && *std::next(it, 1) == *it +1 )
{
next = *std::next(it, 1);
++it;
}

if(next == first)
{
stringList.append(QString::number(*it)+",");
}
else
{
stringList.append(QString::number(first)+"-"+QString::number(next)+",");
}
}

// Remove the last comma
stringList.truncate(stringList.lastIndexOf(QChar(',')));

return stringList;
}

74 changes: 74 additions & 0 deletions Common/SC_OptionSelectionLineEdit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef OPTIONSELECTIONLINEEDIT_H
#define OPTIONSELECTIONLINEEDIT_H
/* *****************************************************************************
Copyright (c) 2016-2021, The Regents of the University of California (Regents).
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS
PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

*************************************************************************** */

// Written by: Sina Naeimi, Stevan Gavrilovic

#include <QLineEdit>

class SC_OptionSelectionLineEdit : public QLineEdit
{
Q_OBJECT

public:
SC_OptionSelectionLineEdit();

void insertSelectedComponent(const int id);

void insertSelectedComponents(const QVector<int>& ids);

void clear();

int size();

// Returns the list of components in a string in the form 1,3,5-6,10,12,...
QString getComponentAnalysisList();

public slots:
void selectComponents(void);

signals:
void componentSelectionComplete(void);

private:

std::set<int> selectedComponentIDs;

QString prevText;
};

#endif // OPTIONSELECTIONLINEEDIT_H