diff --git a/Common/SC_DirEdit.cpp b/Common/SC_DirEdit.cpp index 44ba19231..26e5ced80 100644 --- a/Common/SC_DirEdit.cpp +++ b/Common/SC_DirEdit.cpp @@ -34,7 +34,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. *************************************************************************** */ -// Written: fmckenna +// Written: fmckenna, Sina Naeimi #include @@ -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); + } }); } diff --git a/Common/SC_MultipleLineChart.cpp b/Common/SC_MultipleLineChart.cpp index 41e0593d1..d21558b25 100644 --- a/Common/SC_MultipleLineChart.cpp +++ b/Common/SC_MultipleLineChart.cpp @@ -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; @@ -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) @@ -230,7 +230,7 @@ SC_MultipleLineChart::~SC_MultipleLineChart() } } -int +void SC_MultipleLineChart::setData(QMap *newData) { // @@ -257,5 +257,5 @@ SC_MultipleLineChart::setData(QMap *newData) theSelection->addItem(key); } - return 0; + // return 0; } diff --git a/Common/SC_MultipleLineChart.h b/Common/SC_MultipleLineChart.h index bf3982c2c..fcbfcdd58 100644 --- a/Common/SC_MultipleLineChart.h +++ b/Common/SC_MultipleLineChart.h @@ -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: @@ -136,7 +136,7 @@ class SC_MultipleLineChart : public QWidget { public: SC_MultipleLineChart(QWidget *parent = 0); ~SC_MultipleLineChart(); - int setData(QMap *newData); + void setData(QMap *newData); public slots: diff --git a/Common/SC_OptionSelectionLineEdit.cpp b/Common/SC_OptionSelectionLineEdit.cpp new file mode 100644 index 000000000..ace0d9cd9 --- /dev/null +++ b/Common/SC_OptionSelectionLineEdit.cpp @@ -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 + +#include + +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& 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 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 AssetInputDelegate::getSelectedComponentIDs() const +{ + return selectedComponentIDs; +} + + +QString AssetInputDelegate::getComponentAnalysisList() +{ + QString stringList; + + std::set::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; +} + diff --git a/Common/SC_OptionSelectionLineEdit.h b/Common/SC_OptionSelectionLineEdit.h new file mode 100644 index 000000000..4f0d83e5d --- /dev/null +++ b/Common/SC_OptionSelectionLineEdit.h @@ -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 + +class SC_OptionSelectionLineEdit : public QLineEdit +{ + Q_OBJECT + +public: + SC_OptionSelectionLineEdit(); + + void insertSelectedComponent(const int id); + + void insertSelectedComponents(const QVector& 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 selectedComponentIDs; + + QString prevText; +}; + +#endif // OPTIONSELECTIONLINEEDIT_H