]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Prepare importing of keyframes from clip analysis
[kdenlive] / src / docclipbase.cpp
index 09494c9e83944845e7cba057f2c08f22df7e25eb..d278eeca429e9307f13c6da6feafbe9cd5ff052c 100644 (file)
@@ -73,6 +73,12 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
         }
     }
 
+    if (xml.hasAttribute("analysisdata")) {
+       QStringList adata = xml.attribute("analysisdata").split('#', QString::SkipEmptyParts);
+       for (int i = 0; i < adata.count(); i++)
+           m_analysisdata.insert(adata.at(i).section('?', 0, 0), adata.at(i).section('?', 1, 1));
+    }
+
     KUrl url = KUrl(xml.attribute("resource"));
     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
 
@@ -255,6 +261,16 @@ QDomElement DocClipBase::toXML(bool hideTemporaryProperties) const
         }
         clip.setAttribute("cutzones", cuts.join(";"));
     }
+    QString adata;
+    if (!m_analysisdata.isEmpty()) {
+       QMapIterator<QString, QString> i(m_analysisdata);
+       while (i.hasNext()) {
+           i.next();
+           //WARNING: a ? and # separator is not a good idea
+           adata.append(i.key() + "?" + i.value() + "#");
+       }
+    }
+    clip.setAttribute("analysisdata", adata);
     //kDebug() << "/// CLIP XML: " << doc.toString();
     return doc.documentElement();
 }
@@ -290,22 +306,21 @@ QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
 }
 
 
-void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
+void DocClipBase::addSnapMarker(const CommentedTime marker)
 {
     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
-        if ((*it).time() >= time)
+        if ((*it).time() >= marker.time())
             break;
     }
 
-    if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
-        (*it).setComment(comment);
+    if ((it != m_snapMarkers.end()) && ((*it).time() == marker.time())) {
+        (*it).setComment(marker.comment());
+       (*it).setMarkerType(marker.markerType());
         //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
     } else {
-        CommentedTime t(time, comment);
-        m_snapMarkers.insert(it, t);
+        m_snapMarkers.insert(it, marker);
     }
-
 }
 
 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
@@ -378,10 +393,9 @@ GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
     return duration();
 }
 
-QString DocClipBase::markerComment(GenTime t)
+QString DocClipBase::markerComment(GenTime t) const
 {
-    QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
-
+    QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
     while (itt != m_snapMarkers.end()) {
         if ((*itt).time() == t)
             return (*itt).comment();
@@ -390,6 +404,17 @@ QString DocClipBase::markerComment(GenTime t)
     return QString();
 }
 
+CommentedTime DocClipBase::markerAt(GenTime t) const
+{
+    QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
+    while (itt != m_snapMarkers.end()) {
+        if ((*itt).time() == t)
+            return (*itt);
+        ++itt;
+    }
+    return CommentedTime();
+}
+
 void DocClipBase::clearThumbProducer()
 {
     if (m_thumbProd) m_thumbProd->clearProducer();
@@ -1250,4 +1275,14 @@ QImage DocClipBase::extractImage(int frame, int width, int height)
     return m_thumbProd->extractImage(frame, width, height);
 }
 
+void DocClipBase::setAnalysisData(const QString &name, const QString &data)
+{
+    if (data.isEmpty()) m_analysisdata.remove(name);
+    else m_analysisdata.insert(name, data);
+}
+
+QMap <QString, QString> DocClipBase::analysisData() const
+{
+    return m_analysisdata;
+}