diff --git a/GUI/Model/BaseItem/SessionItem.cpp b/GUI/Model/BaseItem/SessionItem.cpp index 48874bfd0b4242c484175c91cb383a5c318b3bb5..c5bccb2cb244fd38c046b39c6b97ae2a4fea8310 100644 --- a/GUI/Model/BaseItem/SessionItem.cpp +++ b/GUI/Model/BaseItem/SessionItem.cpp @@ -433,11 +433,10 @@ QString SessionItem::itemName() const { return isTag(P_NAME) ? getItemValue(P_NAME).toString() : displayName(); } -#include <QDebug> + //! Set item name, add property if necessary. void SessionItem::setItemName(const QString& name) { - qInfo() << "setItemName" << name << endl; if (isTag(P_NAME)) setItemValue(P_NAME, name); else diff --git a/GUI/Model/Job/JobItem.cpp b/GUI/Model/Job/JobItem.cpp index 776b068f9fab30f9d6106ce936bda4ddabb26dca..dbb220f8cad5b1a1c16f5337636569dcf5af9f6d 100644 --- a/GUI/Model/Job/JobItem.cpp +++ b/GUI/Model/Job/JobItem.cpp @@ -65,11 +65,6 @@ JobItem::JobItem() registerTag(T_FIT_SUITE, 1, 1, {FitSuiteItem::M_TYPE}); } -JobItem::~JobItem() -{ - qInfo() << "deleting JobItem" << this << endl; -} - QString JobItem::getIdentifier() const { return getItemValue(P_IDENTIFIER).toString(); @@ -77,7 +72,8 @@ QString JobItem::getIdentifier() const void JobItem::setIdentifier(const QString& identifier) { - setItemValue(JobItem::P_IDENTIFIER, identifier); + setItemValue(P_IDENTIFIER, identifier); + emit jobIdentifierChanged(identifier); } QString JobItem::jobName() const @@ -214,6 +210,7 @@ QString JobItem::getComments() const void JobItem::setComments(const QString& comments) { setItemValue(P_COMMENTS, comments); + emit jobCommentsChanged(comments); } bool JobItem::isCommentsPropertyName(const QString& name) @@ -229,6 +226,7 @@ int JobItem::getProgress() const void JobItem::setProgress(int progress) { setItemValue(P_PROGRESS, progress); + emit jobProgressChanged(progress); } bool JobItem::isProgressPropertyName(const QString& name) @@ -356,7 +354,8 @@ QString JobItem::instrumentName() const void JobItem::setInstrumentName(const QString& name) { - getItem(P_INSTRUMENT_NAME)->setValue(name); + setItemValue(P_INSTRUMENT_NAME, name); + emit jobInstrumentNameChanged(name); } QString JobItem::presentationType() const @@ -367,6 +366,7 @@ QString JobItem::presentationType() const void JobItem::setPresentationType(const QString& type) { setItemValue(P_PRESENTATION_TYPE, type); + emit jobPresentationTypeChanged(type); } void JobItem::writeNonSessionItems(QXmlStreamWriter* writer) const diff --git a/GUI/Model/Job/JobItem.h b/GUI/Model/Job/JobItem.h index ac12b86ad1f77420d3eb8354d48507b36d89ba0e..545886c1d10a1fde8e2c485ff17e3fc078cd8fb7 100644 --- a/GUI/Model/Job/JobItem.h +++ b/GUI/Model/Job/JobItem.h @@ -62,7 +62,6 @@ public: static constexpr auto M_TYPE{"JobItem"}; JobItem(); - ~JobItem(); QString getIdentifier() const; void setIdentifier(const QString& identifier); @@ -157,6 +156,11 @@ signals: void jobStatusChanged(const JobStatus status); void jobBeginTimeChanged(const QDateTime& begin_time); void jobEndTimeChanged(const QDateTime& end_time); + void jobIdentifierChanged(const QString& identifier); + void jobCommentsChanged(const QString& comments); + void jobProgressChanged(int progress); + void jobInstrumentNameChanged(const QString& name); + void jobPresentationTypeChanged(const QString& type); private: void updateIntensityDataFileName(); diff --git a/GUI/View/Job/JobListModel.cpp b/GUI/View/Job/JobListModel.cpp index 2e3b720c22789369209dfe3025abbfde2f2e0011..22076b11ffecf2a75c635c4b3efbb6a1def0e27c 100644 --- a/GUI/View/Job/JobListModel.cpp +++ b/GUI/View/Job/JobListModel.cpp @@ -29,18 +29,17 @@ JobListModel::JobListModel(JobModel* jobs, QObject* parent) , m_jobs(jobs) { for (JobItem* job : m_jobs->jobItems()) - attachToJob(job); + enableJobNotification(job); connect(jobs, &QAbstractItemModel::rowsAboutToBeInserted, this, &JobListModel::onRowsAboutToBeInserted); connect(jobs, &QAbstractItemModel::rowsInserted, this, &JobListModel::onRowsInserted); } -#include <QDebug> JobListModel::~JobListModel() { for (JobItem* job : m_jobs->jobItems()) { - detachFromJob(job); + disableJobNotification(job); } } @@ -88,7 +87,7 @@ void JobListModel::removeJob(const QModelIndex& index) { beginRemoveRows(QModelIndex(), index.row(), index.row()); JobItem* job = jobForIndex(index); - detachFromJob(job); + disableJobNotification(job); m_jobs->removeJob(job); endRemoveRows(); } @@ -98,6 +97,16 @@ void JobListModel::cancelJob(const QModelIndex& index) m_jobs->cancelJob(jobForIndex(index)); } +void JobListModel::emitJobListModelChanged(JobItem* job) +{ + QVector<JobItem*> jobs = m_jobs->jobItems(); + int i = jobs.indexOf(job); + if (i != -1) { + QModelIndex idx = index(i, 0); + emit dataChanged(idx, idx); + } +} + //-------------------------------------------------------------------------------------------------- // private slots //-------------------------------------------------------------------------------------------------- @@ -114,7 +123,7 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) endInsertRows(); QVector<JobItem*> jobs = m_jobs->jobItems(); for (int i = start; i <= end; i++) - attachToJob(jobs.at(i)); + enableJobNotification(jobs.at(i)); } } @@ -122,28 +131,21 @@ void JobListModel::onRowsInserted(const QModelIndex& parent, int start, int end) // private member functions //-------------------------------------------------------------------------------------------------- -void JobListModel::attachToJob(JobItem* job) -{ - job->mapper()->setOnPropertyChange( - [=](const QString& arg) { notifyJobPropertyChange(job, arg); }); +void JobListModel::enableJobNotification(JobItem* job) +{ + // name + connect(job, &JobItem::jobNameChanged, this, [=](const QString& name){Q_UNUSED(name); + emitJobListModelChanged(job); }, Qt::UniqueConnection); + // status + connect(job, &JobItem::jobStatusChanged, this, [=](const JobStatus status){Q_UNUSED(status); + emitJobListModelChanged(job); }, Qt::UniqueConnection); + // progress + connect(job, &JobItem::jobProgressChanged, this, [=](int progress){Q_UNUSED(progress); + emitJobListModelChanged(job); }, Qt::UniqueConnection); } -void JobListModel::detachFromJob(JobItem* job) +void JobListModel::disableJobNotification(JobItem* job) { - job->mapper()->unsubscribe(this); + disconnect(job, nullptr, this, nullptr); } -void JobListModel::notifyJobPropertyChange(JobItem* job, const QString& property) -{ - if (SessionItem::isItemNamePropertyName(property) - || JobItem::isStatusPropertyName(property) - || JobItem::isProgressPropertyName(property)) { - QVector<JobItem*> jobs = m_jobs->jobItems(); - int i = jobs.indexOf(job); - if (i != -1) { - QModelIndex idx = index(i, 0); -// qInfo() << "notifyJobPropertyChange: " << property<< endl; - emit dataChanged(idx, idx); - } - } -} diff --git a/GUI/View/Job/JobListModel.h b/GUI/View/Job/JobListModel.h index 4dae129b51f014984b21cb6ad3f76d747d41e06c..202ab4203d2f830a8c54d44a86fd6dab3d1bd9bd 100644 --- a/GUI/View/Job/JobListModel.h +++ b/GUI/View/Job/JobListModel.h @@ -39,13 +39,13 @@ public: void cancelJob(const QModelIndex& index); private slots: + void emitJobListModelChanged(JobItem* job); void onRowsAboutToBeInserted(const QModelIndex& parent, int start, int end); void onRowsInserted(const QModelIndex& parent, int start, int end); private: - void attachToJob(JobItem* job); - void detachFromJob(JobItem* job); - void notifyJobPropertyChange(JobItem* job, const QString& property); + void enableJobNotification(JobItem* job); + void disableJobNotification(JobItem* job); private: JobModel* m_jobs; diff --git a/GUI/View/Job/JobListView.cpp b/GUI/View/Job/JobListView.cpp index 6abf93d2130577251e69cfe4c3480de0f971d945..b14bb4a44412e817dfa266411d087cfcd1381cc5 100644 --- a/GUI/View/Job/JobListView.cpp +++ b/GUI/View/Job/JobListView.cpp @@ -98,7 +98,7 @@ JobListView::JobListView(JobModel* jobs, QWidget* parent, Qt::WindowFlags f) connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &JobListView::onItemSelectionChanged); - connect(m_model, &QAbstractItemModel::dataChanged, this, &JobListView::onDataChanged); + connect(m_model, &QAbstractListModel::dataChanged, this, &JobListView::onJobListModelDataChanged); updateActions(); ensureItemSelected(); @@ -138,7 +138,7 @@ void JobListView::onItemSelectionChanged() emit selectedJobsChanged(selectedJobs()); } -void JobListView::onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) +void JobListView::onJobListModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { // currently only single items change, not ranges; thus ranges are not supported ASSERT(topLeft == bottomRight); diff --git a/GUI/View/Job/JobListView.h b/GUI/View/Job/JobListView.h index 817344082e10d97ca5f49096a529c862fb29bd7f..5045223b19a7bb4aded2e946ba599c0920917d37 100644 --- a/GUI/View/Job/JobListView.h +++ b/GUI/View/Job/JobListView.h @@ -40,7 +40,7 @@ signals: private slots: void onItemSelectionChanged(); - void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); + void onJobListModelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); void onRun(); void onCancel(); void onRemove();