diff --git a/include/tracker.h b/include/tracker.h index 157b650d1a60a7843f9640b199e579c0ec37e40d..554dcba2211a7ab07f88d49985d340e33a293956 100644 --- a/include/tracker.h +++ b/include/tracker.h @@ -321,6 +321,17 @@ public: { return mComment; } + /** + * @brief Get the comment without line breaks + * + * Get the comment as a one line QString where all linebreak are replaced with '<br>' + * @return comment without line breaks + */ + inline QString serializeComment() const + { + return QString{mComment}.replace(QRegularExpression("\n"), "<br>"); + } + inline void setComment(QString s) { mComment = s; @@ -388,7 +399,7 @@ inline QTextStream& operator>>(QTextStream& s, TrackPerson& tp) //s.skipWhiteSpace(); // skip white spaces for reading the comment line without this the reading makes some problems // Kommentarzeile lesen str = s.readLine(); - tp.setComment(str); + tp.setComment(str.replace(QRegularExpression("<br>"), "\n")); //cout << " comment: " << tp.comment() << endl; //if ( !comment.isEmpty()) // s.skipWhiteSpace(); @@ -411,7 +422,7 @@ inline QTextStream& operator<<(QTextStream& s, const TrackPerson& tp) s << " " <<tp.getMarkerID(); } s << " " << tp.size(); - s << Qt::endl << tp.comment() << Qt::endl; + s << Qt::endl << tp.serializeComment() << Qt::endl; for (int i = 0; i < tp.size(); ++i) s << tp.at(i) << Qt::endl; return s; @@ -425,7 +436,7 @@ inline std::ostream& operator<<(std::ostream& s, const TrackPerson& tp) s << " " << tp.getMarkerID(); } s << " " << tp.size(); - s << std::endl << tp.comment() << std::endl; + s << std::endl << tp.serializeComment() << std::endl; for (int i = 0; i < tp.size(); ++i) s << tp.at(i) << std::endl; return s; @@ -473,7 +484,7 @@ public: void delPointAll(int direction, int frame); void delPointROI(); void delPointInsideROI(); - bool editTrackPersonComment(const Vec2F& p, int frame, QSet<int> onlyVisible); + bool editTrackPersonComment(const Vec2F& p, int frame, const QSet<int>& onlyVisible); bool setTrackPersonHeight(const Vec2F& p, int frame, QSet<int> onlyVisible); bool resetTrackPersonHeight(const Vec2F& p, int frame, QSet<int> onlyVisible); diff --git a/src/petrack.cpp b/src/petrack.cpp index f4826981f7724e3e3cd3267b10360fe61e54d5c8..cb71f64710896a971d2e34a55dc1337047ce361d 100644 --- a/src/petrack.cpp +++ b/src/petrack.cpp @@ -3166,8 +3166,16 @@ void Petrack::exportTracker(QString dest) //default = "" for(int i=0;i<mTracker->size();++i) { - out << "#" << qSetFieldWidth(3) << (i+1) << qSetFieldWidth(0) << "|" << mTracker->at(i).comment() << Qt::endl; - std::cout << setw(4) << (i+1) << "|" << mTracker->at(i).comment() << std::endl; + auto commentSplit = mTracker->at(i).comment().split("\n", Qt::KeepEmptyParts); + out << "#" << qSetFieldWidth(3) << (i+1) << qSetFieldWidth(0) << "|" << commentSplit.at(0) << Qt::endl; + std::cout << setw(4) << (i+1) << "|" << commentSplit.at(0) << std::endl; + + commentSplit.pop_front(); + for (const auto& line : commentSplit) + { + out << "#" << qSetFieldWidth(3) << " " << qSetFieldWidth(0) << "|" << line << Qt::endl; + std::cout << " |" << line << std::endl; + } } } mTrackerReal->exportTxt(out, diff --git a/src/tracker.cpp b/src/tracker.cpp index e9b40ce893a36a1b3f3492ba7bb6c2d93f35dbf0..1a202af4d0214e30c13a3c34374f8949f80dd3d8 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -873,23 +873,50 @@ void Tracker::delPointROI() } -bool Tracker::editTrackPersonComment(const Vec2F& p, int frame, QSet<int> onlyVisible) -{ - int i; - for (i = 0; i < size(); ++i) // ueber TrackPerson - if (((onlyVisible.empty()) || (onlyVisible.contains(i))) && (at(i).trackPointExist(frame) && (at(i).trackPointAt(frame).distanceToPoint(p) < mMainWindow->getHeadSize(NULL, i, frame)/2.))) // war: MIN_DISTANCE)) // 30 ist abstand zwischen kopfen +/** + * @brief Editing the comment of a TrackPerson + * + * Allows editing the comment of a TrackPerson in a new Dialog. When a new dialog gets opened, it automatically + * appends 'Frame {\p frame}: ' to the dialog, if no comment for the frame exists. + * + * @param p position the user clicked + * @param frame current frame number + * @param onlyVisible list of visible persons + * @return if a comment has been saved + */ +bool Tracker::editTrackPersonComment(const Vec2F& p, int frame, const QSet<int>& onlyVisible) +{ + for (int i = 0; i < size(); ++i) // ueber TrackPerson + { + if (((onlyVisible.empty()) || (onlyVisible.contains(i))) && (at(i).trackPointExist(frame) && + (at(i).trackPointAt(frame).distanceToPoint(p) < + mMainWindow->getHeadSize(nullptr, i, frame) / + 2.))) // war: MIN_DISTANCE)) // 30 ist abstand zwischen kopfen { - bool ok; - QString comment = QInputDialog::getText(mMainWindow,QObject::tr("Add Comment"),QObject::tr("Comment:"), - QLineEdit::Normal, at(i).comment() , &ok); - if (ok) + QString displayedComment = at(i).comment(); + QString framePrefix = "Frame " + QString::number(frame, 'g', 5) + ": "; + + if (displayedComment.isEmpty()) { - if(comment.isEmpty()) - { - int ret = QMessageBox::warning(mMainWindow, QObject::tr("Empty comment"), QObject::tr("Are you sure you want to save an empty comment?"), QMessageBox::Save | QMessageBox::Cancel); - if( ret == QMessageBox::Cancel ) - { + displayedComment.append(framePrefix); + } + else if (!displayedComment.contains(framePrefix)) + { + displayedComment.append("\n" + framePrefix); + } + + bool ok = false; + QString comment = QInputDialog::getMultiLineText(mMainWindow, QObject::tr("Add Comment"), + QObject::tr("Comment:"), + displayedComment, &ok); + + if (ok) { + if (comment.isEmpty()) { + int ret = QMessageBox::warning(mMainWindow, QObject::tr("Empty comment"), + QObject::tr("Are you sure you want to save an empty comment?"), + QMessageBox::Save | QMessageBox::Cancel); + if (ret == QMessageBox::Cancel) { return false; } } @@ -897,6 +924,7 @@ bool Tracker::editTrackPersonComment(const Vec2F& p, int frame, QSet<int> onlyVi return true; } } + } return false; }