Commit f4f3deea authored by Mihail Ivchenko's avatar Mihail Ivchenko

Fix various crashes/issues related to Tours.

Fix flyTo functionality. Now it remembers altitude.
Fix issues related to wrong tour duration handling.
Fix the crash on saving the Tour.
Fix handling of the end of Tour playback.
Fix updating button states in TourWidget
REVIEW: 121783
parent df7b84e0
......@@ -893,4 +893,59 @@ GeoDataDocument * GeoDataTreeModel::rootDocument()
return d->m_rootDocument;
}
int GeoDataTreeModel::addTourPrimitive( const QModelIndex &parent, GeoDataTourPrimitive *primitive, int row )
{
GeoDataObject *parentObject = static_cast<GeoDataObject*>( parent.internalPointer() );
if( parent.isValid() && parentObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( parentObject );
if( row == -1 ) {
row = playlist->size();
}
beginInsertRows( parent, row, row );
playlist->insertPrimitive( row, primitive );
endInsertRows();
return row;
}
return -1;
}
bool GeoDataTreeModel::removeTourPrimitive( const QModelIndex &parent , int index)
{
GeoDataObject *parentObject = static_cast<GeoDataObject*>( parent.internalPointer() );
if( parent.isValid() && parentObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( parentObject );
if( playlist->size() > index ) {
beginRemoveRows( parent, index, index );
playlist->removePrimitiveAt( index );
endRemoveRows();
return true;
}
}
return false;
}
bool GeoDataTreeModel::swapTourPrimitives( const QModelIndex &parent, int indexA, int indexB )
{
GeoDataObject *parentObject = static_cast<GeoDataObject*>( parent.internalPointer() );
if( parent.isValid() && parentObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) {
GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( parentObject );
if( indexA > indexB ) {
qSwap(indexA, indexB);
}
if ( indexB - indexA == 1 ) {
beginMoveRows( parent, indexA, indexA, parent, indexB+1 );
} else {
beginMoveRows( parent, indexA, indexA, parent, indexB );
beginMoveRows( parent, indexB, indexB, parent, indexA );
}
playlist->swapPrimitives( indexA, indexB );
if( indexB - indexA != 1 ) {
endMoveRows();
}
endMoveRows();
return true;
}
return false;
}
#include "GeoDataTreeModel.moc"
......@@ -23,6 +23,7 @@ class GeoDataObject;
class GeoDataDocument;
class GeoDataFeature;
class GeoDataContainer;
class GeoDataTourPrimitive;
/**
......@@ -99,6 +100,10 @@ public Q_SLOTS:
void removeDocument( GeoDataDocument* document );
int addTourPrimitive( const QModelIndex &parent, GeoDataTourPrimitive *primitive, int row = -1 );
bool removeTourPrimitive( const QModelIndex &parent, int index );
bool swapTourPrimitives( const QModelIndex &parent, int indexA, int indexB );
Q_SIGNALS:
/// insert and remove row don't trigger any signal that proxies forward
/// this signal will refresh geometry layer and placemark layout
......
......@@ -18,7 +18,6 @@ namespace Marble
PlaybackWaitItem::PlaybackWaitItem( const GeoDataWait* wait )
{
m_wait = wait;
m_duration = wait->duration();
m_isPlaying = false;
}
const GeoDataWait* PlaybackWaitItem::wait() const
......@@ -27,7 +26,7 @@ const GeoDataWait* PlaybackWaitItem::wait() const
}
double PlaybackWaitItem::duration() const
{
return m_duration;
return m_wait->duration();
}
void PlaybackWaitItem::play()
......@@ -53,7 +52,7 @@ void PlaybackWaitItem::playNext()
}
double const progress = m_start.msecsTo( QDateTime::currentDateTime() ) / 1000.0;
Q_ASSERT( progress >= 0.0 );
double const t = progress / m_duration;
double const t = progress / duration();
if( t <= 1 ){
if( m_isPlaying ){
emit progressChanged( progress );
......@@ -73,7 +72,7 @@ void PlaybackWaitItem::pause()
void PlaybackWaitItem::seek( double t )
{
m_start = QDateTime::currentDateTime().addMSecs( -t * m_duration * 1000 );
m_start = QDateTime::currentDateTime().addMSecs( -t * duration() * 1000 );
m_pause = QDateTime::currentDateTime();
}
......@@ -86,4 +85,4 @@ void PlaybackWaitItem::stop()
}
#include "PlaybackWaitItem.moc"
\ No newline at end of file
#include "PlaybackWaitItem.moc"
......@@ -36,8 +36,7 @@ private:
const GeoDataWait* m_wait;
QDateTime m_start;
QDateTime m_pause;
double m_duration;
bool m_isPlaying;
};
}
#endif
\ No newline at end of file
#endif
......@@ -25,7 +25,6 @@ namespace Marble
SerialTrack::SerialTrack(): QObject()
{
m_currentIndex = 0;
m_duration = 0;
m_finishedPosition = 0;
m_currentPosition = 0;
m_paused = true;
......@@ -43,7 +42,6 @@ void SerialTrack::append(PlaybackItem* item)
connect( item, SIGNAL( finished() ), this, SLOT( handleFinishedItem() ) ) ;
connect( item, SIGNAL( paused() ), this, SLOT( pause() ) ) ;
m_items.append( item );
m_duration += item->duration();
}
void SerialTrack::play()
......@@ -117,14 +115,17 @@ void SerialTrack::seek( double offset )
double SerialTrack::duration() const
{
return m_duration;
double duration = 0.0;
foreach (PlaybackItem* item, m_items) {
duration += item->duration();
}
return duration;
}
void SerialTrack::clear()
{
qDeleteAll( m_items );
m_items.clear();
m_duration = 0;
m_currentIndex = 0;
m_finishedPosition = 0;
m_currentPosition = 0;
......
......@@ -51,7 +51,6 @@ public Q_SLOTS:
private:
QList<PlaybackItem*> m_items;
int m_currentIndex;
double m_duration;
double m_finishedPosition;
double m_currentPosition;
bool m_paused;
......
......@@ -78,6 +78,7 @@ TourPlayback::TourPlayback(QObject *parent) :
connect( &d->m_mainTrack, SIGNAL( centerOn( GeoDataCoordinates ) ), this, SLOT( centerOn( GeoDataCoordinates ) ) );
connect( &d->m_mainTrack, SIGNAL( progressChanged( double ) ), this, SIGNAL( progressChanged( double ) ) );
connect( &d->m_mainTrack, SIGNAL( finished() ), this, SLOT( stopTour() ) );
connect( &d->m_mainTrack, SIGNAL( finished() ), this, SIGNAL( finished() ) );
}
TourPlayback::~TourPlayback()
......
This diff is collapsed.
......@@ -24,6 +24,7 @@ class QModelIndex;
class QDoubleSpinBox;
class QRadioButton;
class QLineEdit;
class QToolButton;
namespace Marble
{
......@@ -48,6 +49,7 @@ class FlyToEditWidget: public QWidget
public:
FlyToEditWidget( const QModelIndex& index, MarbleWidget* widget, QWidget* parent=0 );
bool editable() const;
Q_SIGNALS:
void editingDone( const QModelIndex& index );
......@@ -55,10 +57,14 @@ Q_SIGNALS:
private Q_SLOTS:
void save();
public Q_SLOTS:
void setEditable( bool editable );
private:
GeoDataFlyTo* flyToElement();
MarbleWidget* m_widget;
QModelIndex m_index;
QToolButton *m_button;
};
class TourControlEditWidget: public QWidget
......@@ -67,6 +73,7 @@ class TourControlEditWidget: public QWidget
public:
TourControlEditWidget( const QModelIndex& index, QWidget* parent=0 );
bool editable() const;
Q_SIGNALS:
void editingDone( const QModelIndex& index );
......@@ -74,9 +81,13 @@ Q_SIGNALS:
private Q_SLOTS:
void save();
public Q_SLOTS:
void setEditable( bool editable );
private:
GeoDataTourControl* tourControlElement();
QModelIndex m_index;
QToolButton *m_button;
QRadioButton *m_radio_play;
QRadioButton *m_radio_pause;
};
......@@ -87,6 +98,7 @@ class WaitEditWidget: public QWidget
public:
WaitEditWidget( const QModelIndex& index, QWidget* parent=0 );
bool editable() const;
Q_SIGNALS:
void editingDone( const QModelIndex& index );
......@@ -94,9 +106,13 @@ Q_SIGNALS:
private Q_SLOTS:
void save();
public Q_SLOTS:
void setEditable( bool editable );
private:
GeoDataWait* waitElement();
QModelIndex m_index;
QToolButton *m_button;
QDoubleSpinBox *m_spinBox;
};
......@@ -106,6 +122,7 @@ class SoundCueEditWidget: public QWidget
public:
SoundCueEditWidget( const QModelIndex& index, QWidget* parent=0 );
bool editable() const;
Q_SIGNALS:
void editingDone( const QModelIndex& index );
......@@ -113,9 +130,13 @@ Q_SIGNALS:
private Q_SLOTS:
void save();
public Q_SLOTS:
void setEditable( bool editable );
private:
GeoDataSoundCue* soundCueElement();
QModelIndex m_index;
QToolButton *m_button;
QLineEdit* m_lineEdit;
};
......@@ -147,6 +168,7 @@ private Q_SLOTS:
void moveDown();
void addFlyTo();
void deleteSelected();
void updateDuration();
private:
Q_PRIVATE_SLOT( d, void openFile() )
......@@ -172,9 +194,13 @@ public:
void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const;
QWidget* createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
bool editable() const;
void setEditable( bool editable );
Q_SIGNALS:
void editingChanged( QModelIndex index );
void edited( QModelIndex index );
void editableChanged( bool editable );
public:
......@@ -196,6 +222,7 @@ private:
QList<QPersistentModelIndex> m_editingIndices;
QListView* m_listView;
MarbleWidget *m_widget;
bool m_editable;
};
}
......
......@@ -409,15 +409,20 @@ void GeometryLayer::addPlacemarks( QModelIndex parent, int first, int last )
void GeometryLayer::removePlacemarks( QModelIndex parent, int first, int last )
{
Q_ASSERT( last < d->m_model->rowCount( parent ) );
bool isRepaintNeeded = false;
for( int i=first; i<=last; ++i ) {
QModelIndex index = d->m_model->index( i, 0, parent );
Q_ASSERT( index.isValid() );
const GeoDataObject *object = qvariant_cast<GeoDataObject*>(index.data( MarblePlacemarkModel::ObjectPointerRole ) );
const GeoDataFeature *feature = dynamic_cast<const GeoDataFeature*>( object );
Q_ASSERT( feature );
d->removeGraphicsItems( feature );
if( feature != 0 ) {
d->removeGraphicsItems( feature );
isRepaintNeeded = true;
}
}
if( isRepaintNeeded ) {
emit repaintNeeded();
}
emit repaintNeeded();
}
......
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