"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/backend/core/Project.cpp" between
labplot-2.8.1.tar.gz and labplot-2.8.2.tar.gz

About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.

Project.cpp  (labplot-2.8.1):Project.cpp  (labplot-2.8.2)
skipping to change at line 225 skipping to change at line 225
/*! /*!
* \brief Project::descriptionChanged * \brief Project::descriptionChanged
* This function is called, when an object changes its name. When a column chang ed its name and wasn't connected before to the curve/column(formula) then * This function is called, when an object changes its name. When a column chang ed its name and wasn't connected before to the curve/column(formula) then
* this is done in this function * this is done in this function
* \param aspect * \param aspect
*/ */
void Project::descriptionChanged(const AbstractAspect* aspect) { void Project::descriptionChanged(const AbstractAspect* aspect) {
if (isLoading()) if (isLoading())
return; return;
if (this != aspect) { //when the name of a column is being changed, it can match again the name
const auto* column = dynamic_cast<const AbstractColumn*>(aspect); s being used in the curves, etc.
if (!column) //and we need to update the dependencies
return; const auto* column = dynamic_cast<const AbstractColumn*>(aspect);
if (column) {
// When the column is created, it gets a random name and is event const auto& curves = children<XYCurve>(ChildIndexFlag::Recursive)
ually not connected to any curve. ;
// When changing the name it can match a curve and should than be updateCurveColumnDependencies(curves, column);
connected to the curve.
const QVector<XYCurve*>& curves = children<XYCurve>(ChildIndexFla
g::Recursive);
QString columnPath = column->path();
// setXColumnPath must not be set, because if curve->column match
es column, there already exist a
// signal/slot connection between the curve and the column to upd
ate this. If they are not same,
// xColumnPath is set in setXColumn. Same for the yColumn.
for (auto* curve : curves) {
curve->setUndoAware(false);
auto* analysisCurve = dynamic_cast<XYAnalysisCurve*>(curv
e);
if (analysisCurve) {
if (analysisCurve->xDataColumnPath() == columnPat
h)
analysisCurve->setXDataColumn(column);
if (analysisCurve->yDataColumnPath() == columnPat
h)
analysisCurve->setYDataColumn(column);
if (analysisCurve->y2DataColumnPath() == columnPa
th)
analysisCurve->setY2DataColumn(column);
auto* fitCurve = dynamic_cast<XYFitCurve*>(curve)
;
if (fitCurve) {
if (fitCurve->xErrorColumnPath() == colum
nPath)
fitCurve->setXErrorColumn(column)
;
if (fitCurve->yErrorColumnPath() == colum
nPath)
fitCurve->setYErrorColumn(column)
;
}
} else {
if (curve->xColumnPath() == columnPath)
curve->setXColumn(column);
if (curve->yColumnPath() == columnPath)
curve->setYColumn(column);
if (curve->valuesColumnPath() == columnPath)
curve->setValuesColumn(column);
if (curve->xErrorPlusColumnPath() == columnPath)
curve->setXErrorPlusColumn(column);
if (curve->xErrorMinusColumnPath() == columnPath)
curve->setXErrorMinusColumn(column);
if (curve->yErrorPlusColumnPath() == columnPath)
curve->setYErrorPlusColumn(column);
if (curve->yErrorMinusColumnPath() == columnPath)
curve->setYErrorMinusColumn(column);
}
curve->setUndoAware(true);
}
const QVector<Column*>& columns = children<Column>(ChildIndexFlag const auto& histograms = children<Histogram>(ChildIndexFlag::Recu
::Recursive); rsive);
for (auto* tempColumn : columns) { updateHistogramColumnDependencies(histograms, column);
const QStringList& formulaVariableColumnsPath = tempColum
n->formulaVariableColumnPaths();
for (int i = 0; i < formulaVariableColumnsPath.count(); i
++) {
if (formulaVariableColumnsPath.at(i) == columnPat
h)
tempColumn->setformulVariableColumn(i, co
nst_cast<Column*>(static_cast<const Column*>(column)));
}
}
return;
} }
d->changed = true; d->changed = true;
emit changed(); emit changed();
} }
/*! /*!
* \brief Project::aspectAddedSlot * \brief Project::aspectAddedSlot
* When adding new columns, these should be connected to the corresponding curve s * When adding new columns, these should be connected to the corresponding curve s
* \param aspect * \param aspect
*/ */
void Project::aspectAddedSlot(const AbstractAspect* aspect) { void Project::aspectAddedSlot(const AbstractAspect* aspect) {
//check whether new columns were added and if yes,
const QVector<AbstractAspect*>& _children = aspect->children(AspectType:: //update the dependencies in the project
Column, ChildIndexFlag::Recursive);
QVector<const AbstractColumn*> columns; QVector<const AbstractColumn*> columns;
for (auto child : _children)
columns.append(static_cast<const AbstractColumn*>(child));
const auto* column = dynamic_cast<const AbstractColumn*>(aspect); const auto* column = dynamic_cast<const AbstractColumn*>(aspect);
if (column) if (column)
columns.append(column); columns.append(column);
else {
for (auto* child : aspect->children<Column>(ChildIndexFlag::Recur
sive))
columns.append(static_cast<const AbstractColumn*>(child))
;
}
if (columns.isEmpty()) if (columns.isEmpty())
return; return;
for (auto column : columns) { //if a new column was addded, check whether the column names match the mi
const QVector<XYCurve*>& curves = children<XYCurve>(ChildIndexFla ssing
g::Recursive); //names in the curves, etc. and update the dependencies
QString columnPath = column->path(); const auto& curves = children<XYCurve>(ChildIndexFlag::Recursive);
for (auto column : columns)
updateCurveColumnDependencies(curves, column);
const auto& histograms = children<Histogram>(ChildIndexFlag::Recursive);
for (auto column : columns)
updateHistogramColumnDependencies(histograms, column);
}
for (auto* curve : curves) { void Project::updateCurveColumnDependencies(const QVector<XYCurve*>& curves, con
curve->setUndoAware(false); st AbstractColumn* column) const {
auto* analysisCurve = dynamic_cast<XYAnalysisCurve*>(curv const QString& columnPath = column->path();
e);
if (analysisCurve) {
if (analysisCurve->xDataColumnPath() == columnPat
h)
analysisCurve->setXDataColumn(column);
if (analysisCurve->yDataColumnPath() == columnPat
h)
analysisCurve->setYDataColumn(column);
if (analysisCurve->y2DataColumnPath() == columnPa
th)
analysisCurve->setY2DataColumn(column);
auto* fitCurve = dynamic_cast<XYFitCurve*>(curve) // setXColumnPath must not be set, because if curve->column matches colum
; n, there already exist a
if (fitCurve) { // signal/slot connection between the curve and the column to update this
if (fitCurve->xErrorColumnPath() == colum . If they are not same,
nPath) // xColumnPath is set in setXColumn. Same for the yColumn.
fitCurve->setXErrorColumn(column) for (auto* curve : curves) {
; curve->setUndoAware(false);
if (fitCurve->yErrorColumnPath() == colum auto* analysisCurve = dynamic_cast<XYAnalysisCurve*>(curve);
nPath) if (analysisCurve) {
fitCurve->setYErrorColumn(column) if (analysisCurve->xDataColumnPath() == columnPath)
; analysisCurve->setXDataColumn(column);
} if (analysisCurve->yDataColumnPath() == columnPath)
} else { analysisCurve->setYDataColumn(column);
if (curve->xColumnPath() == columnPath) if (analysisCurve->y2DataColumnPath() == columnPath)
curve->setXColumn(column); analysisCurve->setY2DataColumn(column);
if (curve->yColumnPath() == columnPath)
curve->setYColumn(column); auto* fitCurve = dynamic_cast<XYFitCurve*>(curve);
if (curve->valuesColumnPath() == columnPath) if (fitCurve) {
curve->setValuesColumn(column); if (fitCurve->xErrorColumnPath() == columnPath)
if (curve->xErrorPlusColumnPath() == columnPath) fitCurve->setXErrorColumn(column);
curve->setXErrorPlusColumn(column); if (fitCurve->yErrorColumnPath() == columnPath)
if (curve->xErrorMinusColumnPath() == columnPath) fitCurve->setYErrorColumn(column);
curve->setXErrorMinusColumn(column);
if (curve->yErrorPlusColumnPath() == columnPath)
curve->setYErrorPlusColumn(column);
if (curve->yErrorMinusColumnPath() == columnPath)
curve->setYErrorMinusColumn(column);
}
curve->setUndoAware(true);
}
const QVector<Column*>& columns = children<Column>(ChildIndexFlag
::Recursive);
for (auto* tempColumn : columns) {
const QStringList& formulaVariableColumnPaths = tempColum
n->formulaVariableColumnPaths();
for (int i = 0; i < formulaVariableColumnPaths.count(); i
++) {
if (formulaVariableColumnPaths.at(i) == column->p
ath())
tempColumn->setformulVariableColumn(i, co
nst_cast<Column*>(static_cast<const Column*>(column)));
} }
} else {
if (curve->xColumnPath() == columnPath)
curve->setXColumn(column);
if (curve->yColumnPath() == columnPath)
curve->setYColumn(column);
if (curve->valuesColumnPath() == columnPath)
curve->setValuesColumn(column);
if (curve->xErrorPlusColumnPath() == columnPath)
curve->setXErrorPlusColumn(column);
if (curve->xErrorMinusColumnPath() == columnPath)
curve->setXErrorMinusColumn(column);
if (curve->yErrorPlusColumnPath() == columnPath)
curve->setYErrorPlusColumn(column);
if (curve->yErrorMinusColumnPath() == columnPath)
curve->setYErrorMinusColumn(column);
} }
if (curve->valuesColumnPath() == columnPath)
curve->setValuesColumn(column);
curve->setUndoAware(true);
} }
const QVector<Column*>& columns = children<Column>(ChildIndexFlag::Recurs
ive);
for (auto* tempColumn : columns) {
const QStringList& paths = tempColumn->formulaVariableColumnPaths
();
for (int i = 0; i < paths.count(); i++) {
if (paths.at(i) == columnPath)
tempColumn->setformulVariableColumn(i, const_cast
<Column*>(static_cast<const Column*>(column)));
}
}
} }
void Project::updateHistogramColumnDependencies(const QVector<Histogram*>& histo
grams, const AbstractColumn* column) const {
const QString& columnPath = column->path();
for (auto* histogram : histograms) {
if (histogram->dataColumnPath() == columnPath) {
histogram->setUndoAware(false);
histogram->setDataColumn(column);
histogram->setUndoAware(true);
}
if (histogram->valuesColumnPath() == columnPath) {
histogram->setUndoAware(false);
histogram->setValuesColumn(column);
histogram->setUndoAware(true);
}
}
}
void Project::navigateTo(const QString& path) { void Project::navigateTo(const QString& path) {
emit requestNavigateTo(path); emit requestNavigateTo(path);
} }
bool Project::isLabPlotProject(const QString& fileName) { bool Project::isLabPlotProject(const QString& fileName) {
return fileName.endsWith(QStringLiteral(".lml"), Qt::CaseInsensitive) || return fileName.endsWith(QStringLiteral(".lml"), Qt::CaseInsensitive)
fileName.endsWith(QStringLiteral(".lml.gz"), Qt::CaseInsensitive) || fileName.endsWith(QStringLiteral(".lml.gz"), Qt::CaseI
|| fileName.endsWith(QStringLiteral(".lml.bz2"), Qt::CaseInsensit nsensitive)
ive) || fileName.endsWith(QStringLiteral(".lml.xz"), Qt::CaseInsensitive); || fileName.endsWith(QStringLiteral(".lml.bz2"), Qt::Case
Insensitive)
|| fileName.endsWith(QStringLiteral(".lml.xz"), Qt::CaseI
nsensitive);
} }
QString Project::supportedExtensions() { QString Project::supportedExtensions() {
static const QString extensions = "*.lml *.lml.gz *.lml.bz2 *.lml.xz *.LM L *.LML.GZ *.LML.BZ2 *.LML.XZ"; static const QString extensions = "*.lml *.lml.gz *.lml.bz2 *.lml.xz *.LM L *.LML.GZ *.LML.BZ2 *.LML.XZ";
return extensions; return extensions;
} }
QVector<quintptr> Project::droppedAspects(const QMimeData* mimeData) { QVector<quintptr> Project::droppedAspects(const QMimeData* mimeData) {
QByteArray data = mimeData->data(QLatin1String("labplot-dnd")); QByteArray data = mimeData->data(QLatin1String("labplot-dnd"));
QDataStream stream(&data, QIODevice::ReadOnly); QDataStream stream(&data, QIODevice::ReadOnly);
skipping to change at line 481 skipping to change at line 465
XmlStreamReader reader(file); XmlStreamReader reader(file);
setIsLoading(true); setIsLoading(true);
rc = this->load(&reader, preview); rc = this->load(&reader, preview);
setIsLoading(false); setIsLoading(false);
if (rc == false) { if (rc == false) {
RESET_CURSOR; RESET_CURSOR;
QString msg = reader.errorString(); QString msg = reader.errorString();
if (msg.isEmpty()) if (msg.isEmpty())
msg = i18n("Unknown error when opening the project %1.", filename); msg = i18n("Unknown error when opening the project %1.", filename);
KMessageBox::error(nullptr, msg, i18n("Error when opening the pro ject")); KMessageBox::error(nullptr, msg, i18n("Error when opening the pro ject"));
file->close();
delete file;
return false; return false;
} }
if (reader.hasWarnings()) { if (reader.hasWarnings()) {
qWarning("The following problems occurred when loading the projec t file:"); qWarning("The following problems occurred when loading the projec t file:");
const QStringList& warnings = reader.warningStrings(); const QStringList& warnings = reader.warningStrings();
for (const auto& str : warnings) for (const auto& str : warnings)
qWarning() << qUtf8Printable(str); qWarning() << qUtf8Printable(str);
//TODO: show warnings in a kind of "log window" but not in message box //TODO: show warnings in a kind of "log window" but not in message box
// KMessageBox::error(this, msg, i18n("Project loading partly failed ")); // KMessageBox::error(this, msg, i18n("Project loading partly failed "));
} }
if (reader.hasMissingCASWarnings()) {
RESET_CURSOR;
const QString& msg = i18n("The project has content written with %
1. "
"Your installation of LabPlot lac
ks the support for it.\n\n "
"You won't be able to see this pa
rt of the project. "
"If you modify and save the proje
ct, the CAS content will be lost.\n\n"
"Do you want to continue?", reade
r.missingCASWarning());
auto rc = KMessageBox::warningYesNo(nullptr, msg, i18n("Missing S
upport for CAS"));
if (rc == KMessageBox::ButtonCode::No) {
file->close();
delete file;
return false;
}
}
file->close(); file->close();
delete file; delete file;
return true; return true;
} }
/** /**
* \brief Load from XML * \brief Load from XML
*/ */
bool Project::load(XmlStreamReader* reader, bool preview) { bool Project::load(XmlStreamReader* reader, bool preview) {
skipping to change at line 616 skipping to change at line 618
if (!axis) continue; if (!axis) continue;
RESTORE_COLUMN_POINTER(axis, majorTicksColumn, MajorTicks Column); RESTORE_COLUMN_POINTER(axis, majorTicksColumn, MajorTicks Column);
RESTORE_COLUMN_POINTER(axis, minorTicksColumn, MinorTicks Column); RESTORE_COLUMN_POINTER(axis, minorTicksColumn, MinorTicks Column);
} }
//histograms //histograms
auto hists = children<Histogram>(ChildIndexFlag::Recursive); auto hists = children<Histogram>(ChildIndexFlag::Recursive);
for (auto* hist : hists) { for (auto* hist : hists) {
if (!hist) continue; if (!hist) continue;
RESTORE_COLUMN_POINTER(hist, dataColumn, DataColumn); RESTORE_COLUMN_POINTER(hist, dataColumn, DataColumn);
RESTORE_COLUMN_POINTER(hist, valuesColumn, ValuesColumn);
} }
//data picker curves //data picker curves
auto dataPickerCurves = children<DatapickerCurve>(ChildIndexFlag: :Recursive); auto dataPickerCurves = children<DatapickerCurve>(ChildIndexFlag: :Recursive);
for (auto* dataPickerCurve : dataPickerCurves) { for (auto* dataPickerCurve : dataPickerCurves) {
if (!dataPickerCurve) continue; if (!dataPickerCurve) continue;
RESTORE_COLUMN_POINTER(dataPickerCurve, posXColumn, PosXC olumn); RESTORE_COLUMN_POINTER(dataPickerCurve, posXColumn, PosXC olumn);
RESTORE_COLUMN_POINTER(dataPickerCurve, posYColumn, PosYC olumn); RESTORE_COLUMN_POINTER(dataPickerCurve, posYColumn, PosYC olumn);
RESTORE_COLUMN_POINTER(dataPickerCurve, plusDeltaXColumn, PlusDeltaXColumn); RESTORE_COLUMN_POINTER(dataPickerCurve, plusDeltaXColumn, PlusDeltaXColumn);
RESTORE_COLUMN_POINTER(dataPickerCurve, minusDeltaXColumn , MinusDeltaXColumn); RESTORE_COLUMN_POINTER(dataPickerCurve, minusDeltaXColumn , MinusDeltaXColumn);
 End of changes. 16 change blocks. 
147 lines changed or deleted 135 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)