Commit 4b897bbb authored by Adrien Maglo's avatar Adrien Maglo

Qt/EPG: Remove channels when they don't have any item.

parent daae8e52
...@@ -112,7 +112,12 @@ int EPGItem::duration() const ...@@ -112,7 +112,12 @@ int EPGItem::duration() const
return m_duration; return m_duration;
} }
void EPGItem::setChannel( int channelNb ) int EPGItem::getChannelNb() const
{
return m_channelNb;
}
void EPGItem::setChannelNb( int channelNb )
{ {
//qDebug() << "Channel" << channelNb; //qDebug() << "Channel" << channelNb;
m_channelNb = channelNb; m_channelNb = channelNb;
......
...@@ -44,8 +44,9 @@ public: ...@@ -44,8 +44,9 @@ public:
const QDateTime& start() const; const QDateTime& start() const;
int duration() const; int duration() const;
int getChannelNb() const;
void setChannel( int channelNb ); void setChannelNb( int channelNb );
void setStart( const QDateTime& start ); void setStart( const QDateTime& start );
void setDuration( int duration ); void setDuration( int duration );
void setName( const QString& name ); void setName( const QString& name );
......
...@@ -92,7 +92,7 @@ void EPGView::addEvent( EPGEvent* event ) ...@@ -92,7 +92,7 @@ void EPGView::addEvent( EPGEvent* event )
m_channels.append( event->channelName ); m_channels.append( event->channelName );
EPGItem* item = new EPGItem( this ); EPGItem* item = new EPGItem( this );
item->setChannel( m_channels.indexOf( event->channelName ) ); item->setChannelNb( m_channels.indexOf( event->channelName ) );
item->setStart( event->start ); item->setStart( event->start );
item->setDuration( event->duration ); item->setDuration( event->duration );
item->setName( event->name ); item->setName( event->name );
...@@ -107,9 +107,45 @@ void EPGView::addEvent( EPGEvent* event ) ...@@ -107,9 +107,45 @@ void EPGView::addEvent( EPGEvent* event )
void EPGView::delEvent( EPGEvent* event ) void EPGView::delEvent( EPGEvent* event )
{ {
if( event->item != NULL ) if( event->item == NULL )
scene()->removeItem( event->item ); return;
int channelNb = event->item->getChannelNb();
// Remove the item.
scene()->removeItem( event->item );
event->item = NULL; event->item = NULL;
// Look if the channel is still used by other events.
QList<QGraphicsItem*> itemList = items();
bool b_used = false;
for( int i = 0; i < itemList.count(); ++i )
{
EPGItem* item = qgraphicsitem_cast<EPGItem*>( itemList.at( i ) );
if ( !item )
continue;
if( item->getChannelNb() == channelNb )
{
b_used = true;
break;
}
}
// If the channel is no more used, then we remove it from the list
// and decrease the channel number of the concerned items.
if( !b_used )
{
m_channels.removeAt( channelNb );
for( int i = 0; i < itemList.count(); ++i )
{
EPGItem* item = qgraphicsitem_cast<EPGItem*>( itemList.at( i ) );
if ( !item )
continue;
int itemChannelNb = item->getChannelNb();
if( itemChannelNb > channelNb )
item->setChannelNb( itemChannelNb - 1 );
}
}
} }
void EPGView::updateDuration() void EPGView::updateDuration()
......
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