Fix crash when changing project fps if timeline contains groups

BUG: 368601
parent 9f178986
......@@ -1435,7 +1435,7 @@ void KdenliveDoc::updateProjectProfile(bool reloadProducers)
KdenliveSettings::setProject_fps(fps);
m_width = m_profile.width;
m_height = m_profile.height;
bool fpsChanged = m_timecode.fps() != fps;
double fpsChanged = m_timecode.fps() / fps;
m_timecode.setFormat(fps);
KdenliveSettings::setCurrent_profile(m_profile.path);
pCore->monitorManager()->resetProfiles(m_profile, m_timecode);
......
......@@ -256,8 +256,8 @@ signals:
void startAutoSave();
/** @brief Current doc created effects, reload list */
void reloadEffects();
/** @brief Fps was changed, update timeline */
void updateFps(bool changed);
/** @brief Fps was changed, update timeline (changed = 1 means no change) */
void updateFps(double changed);
/** @brief If a command is pushed when we are in the middle of undo stack, invalidate further undo history */
void removeInvalidUndo(int ix);
/** @brief Update compositing info */
......
......@@ -293,11 +293,30 @@ int CustomTrackView::getFrameWidth() const
return (int) (m_tracksHeight * m_document->dar() + 0.5);
}
void CustomTrackView::updateSceneFrameWidth(bool fpsChanged)
void CustomTrackView::updateSceneFrameWidth(double fpsChanged)
{
int frameWidth = getFrameWidth();
if (fpsChanged && m_projectDuration > 0) {
if (fpsChanged != 1.0 && m_projectDuration > 0) {
// try to remember and rebuild groups
// Prepare groups for reload
QDomDocument doc;
doc.setContent(m_document->groupsXml());
QDomNodeList groups;
if (!doc.isNull()) {
groups = doc.documentElement().elementsByTagName("group");
for (int nodeindex = 0; nodeindex < groups.count(); ++nodeindex) {
QDomNode grp = groups.item(nodeindex);
QDomNodeList nodes = grp.childNodes();
for (int itemindex = 0; itemindex < nodes.count(); ++itemindex) {
QDomElement elem = nodes.item(itemindex).toElement();
if (!elem.hasAttribute(QStringLiteral("position"))) continue;
int pos = elem.attribute(QStringLiteral("position")).toInt();
elem.setAttribute(QStringLiteral("position"), rintf(pos * fpsChanged));
}
}
}
reloadTimeline();
loadGroups(groups);
} else {
QList<QGraphicsItem *> itemList = items();
ClipItem *item;
......@@ -3547,6 +3566,7 @@ void CustomTrackView::addTrack(const TrackInfo &type, int ix)
void CustomTrackView::reloadTimeline()
{
removeTipAnimation();
m_document->clipManager()->resetGroups();
emit clipItemSelected(NULL);
emit transitionItemSelected(NULL);
QList<QGraphicsItem *> selection = m_scene->items();
......@@ -7032,7 +7052,6 @@ void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTim
void CustomTrackView::loadGroups(const QDomNodeList &groups)
{
m_document->clipManager()->resetGroups();
for (int i = 0; i < groups.count(); ++i) {
QDomNodeList children = groups.at(i).childNodes();
scene()->clearSelection();
......
......@@ -105,7 +105,7 @@ public:
void cutSelectedClips(QList<QGraphicsItem *> itemList = QList<QGraphicsItem *>(), GenTime currentPos = GenTime());
void setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transition, QActionGroup *clipTypeGroup, QMenu *markermenu);
bool checkTrackHeight(bool force = false);
void updateSceneFrameWidth(bool fpsChanged = false);
void updateSceneFrameWidth(double fpsChanged = 1.0);
void setTool(ProjectTool tool);
void cutClip(const ItemInfo &info, const GenTime &cutTime, bool cut, const EffectsList &oldStack = EffectsList(), bool execute = true);
Transition *cutTransition(const ItemInfo &info, const GenTime &cutTime, bool cut, const QDomElement &oldStack = QDomElement(), bool execute = true);
......
......@@ -1306,7 +1306,7 @@ void Timeline::slotSaveTimelinePreview(const QString &path)
img.save(path);
}
void Timeline::updateProfile(bool fpsChanged)
void Timeline::updateProfile(double fpsChanged)
{
m_ruler->updateFrameSize();
m_ruler->updateProjectFps(m_doc->timecode());
......
......@@ -199,7 +199,7 @@ public slots:
void slotSaveTimelinePreview(const QString &path);
void checkDuration();
void slotShowTrackEffects(int);
void updateProfile(bool fpsChanged);
void updateProfile(double fpsChanged);
/** @brief Enable/disable multitrack view (split monitor in 4) */
void slotMultitrackView(bool enable);
/** @brief Stop rendering preview. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment