diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index 8ec5f9cfcd609603be19c683cbbaef932c2e0715..8b215c28c5a28d3c323b63860306932850b381b2 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -78,6 +78,19 @@ IntensityDataItem::IntensityDataItem() : SessionItem(Constants::IntensityDataTyp setDefaultTag(T_MASKS); registerTag(T_PROJECTIONS, 0, -1, QStringList() << Constants::ProjectionContainerType); + + mapper()->setOnPropertyChange([this](const QString& name) + { + if(name == P_FILE_NAME) + setLastModified(QDateTime::currentDateTime()); + }); + + mapper()->setOnValueChange([this]() + { + // OutputData was modified + setLastModified(QDateTime::currentDateTime()); + }); + } void IntensityDataItem::setOutputData(OutputData<double>* data) @@ -395,3 +408,13 @@ ProjectionContainerItem* IntensityDataItem::projectionContainerItem() { return dynamic_cast<ProjectionContainerItem*>(getItem(IntensityDataItem::T_PROJECTIONS)); } + +QDateTime IntensityDataItem::lastModified() const +{ + return m_last_modified; +} + +void IntensityDataItem::setLastModified(const QDateTime &dtime) +{ + m_last_modified = dtime; +} diff --git a/GUI/coregui/Models/IntensityDataItem.h b/GUI/coregui/Models/IntensityDataItem.h index 0f861ce908c26090f59e936ced36f5e8c0dba818..d6f2f84aa12eee1126f69829139bb6a6b469b90e 100644 --- a/GUI/coregui/Models/IntensityDataItem.h +++ b/GUI/coregui/Models/IntensityDataItem.h @@ -19,6 +19,7 @@ #include "SessionItem.h" #include "OutputData.h" +#include <QDateTime> class BasicAxisItem; class MaskContainerItem; @@ -99,6 +100,9 @@ public: MaskContainerItem* maskContainerItem(); ProjectionContainerItem* projectionContainerItem(); + QDateTime lastModified() const; + void setLastModified(const QDateTime& dtime); + public slots: void setLowerX(double xmin); void setUpperX(double xmax); @@ -118,6 +122,7 @@ private: void updateAxesLabels(); std::unique_ptr<OutputData<double>> m_data; //!< simulation results + QDateTime m_last_modified; }; #endif // INTENSITYDATAITEM_H diff --git a/Tests/UnitTests/GUI/TestGUI.cpp b/Tests/UnitTests/GUI/TestGUI.cpp index 426cea7a4794dfe63b22fc38fa9d1be3eaac0809..5fa94792dd797bf1a9a908ee2c3502aa3088f480 100644 --- a/Tests/UnitTests/GUI/TestGUI.cpp +++ b/Tests/UnitTests/GUI/TestGUI.cpp @@ -26,6 +26,7 @@ #include "TestProjectDocument.h" #include "TestAutosave.h" #include "TestOutputDataIOService.h" +#include "TestIntensityDataItem.h" int main(int argc, char** argv) { QCoreApplication app(argc, argv); @@ -58,6 +59,7 @@ int main(int argc, char** argv) { TestProjectDocument testProjectDocument; TestAutosave testAutosave; TestOutputDataIOService testIO; + TestIntensityDataItem testIntensityData; bool status(false); @@ -88,6 +90,7 @@ int main(int argc, char** argv) { status |= QTest::qExec(&testProjectDocument, argc, argv); status |= QTest::qExec(&testAutosave, argc, argv); status |= QTest::qExec(&testIO, argc, argv); + status |= QTest::qExec(&testIntensityData, argc, argv); return status; } diff --git a/Tests/UnitTests/GUI/TestIntensityDataItem.h b/Tests/UnitTests/GUI/TestIntensityDataItem.h new file mode 100644 index 0000000000000000000000000000000000000000..d80dd0671abc4796fba8459a010c425961054d8e --- /dev/null +++ b/Tests/UnitTests/GUI/TestIntensityDataItem.h @@ -0,0 +1,39 @@ +#include <QtTest> +#include "SessionModel.h" +#include "IntensityDataItem.h" +#include <QDebug> + +class TestIntensityDataItem : public QObject +{ + Q_OBJECT + +private slots: + void test_lastModified(); +}; + +inline void TestIntensityDataItem::test_lastModified() +{ + SessionModel model("TempModel"); + IntensityDataItem* item = dynamic_cast<IntensityDataItem*>( + model.insertNewItem(Constants::IntensityDataType)); + + QDateTime time = QDateTime::currentDateTime(); + item->setLastModified(time); + QVERIFY(time == item->lastModified()); + + const int nap_time(10); + QTest::qSleep(nap_time); + + // changing item (file name) + item->setItemValue(IntensityDataItem::P_FILE_NAME, "name.txt"); + QDateTime time2 = item->lastModified(); + QVERIFY(time.msecsTo(time2) >= nap_time); + + QTest::qSleep(nap_time); + + // changing item (OutputData) + item->emitDataChanged(); + QDateTime time3 = item->lastModified(); + QVERIFY(time2.msecsTo(time3) >= nap_time); +} +