added select options into playlistmodel

This commit is contained in:
adamsjensen 2018-03-06 13:28:42 +03:00
parent ffd1faa1a1
commit ad11f78182
4 changed files with 92 additions and 0 deletions

View File

@ -87,3 +87,58 @@ void PlayListModel::setNewPlayList(const QString &playList){
playListName = playList;
onPlayListChanged();
}
bool PlayListModel::select(int id){
if(!playList)
return false;
for(QList<syncLib::SongHeader>::Iterator i = 0; i < playList->end(); i++){
if(i->id == id){
return i->isSelected = true;
}
}
return false;
}
bool PlayListModel::unSelect(int id){
if(!playList)
return false;
for(QList<syncLib::SongHeader>::Iterator i = 0; i < playList->end(); i++){
if(i->id == id){
i->isSelected = false;
return true;
}
}
return false;
}
QList<int> PlayListModel::getSelected(){
QList<int> result;
if(!playList)
return result;
for(QList<syncLib::SongHeader>::Iterator i = 0; i < playList->end(); i++){
if(i->isSelected){
result.push_back(i->id);
}
}
return result;
}
bool PlayListModel::isSelected(int id){
if(!playList)
return false;
for(QList<syncLib::SongHeader>::Iterator i = 0; i < playList->end(); i++){
if(i->id == id){
return i->isSelected;
}
}
return false;
}

View File

@ -79,6 +79,33 @@ public slots:
* @param playList - name of playlist
*/
void setNewPlayList(const QString &playList);
/**
* @brief select a song from playList;
* @param id - if of song
* @return true if all done
*/
bool select(int id);
/**
* @brief unselect a song from playList;
* @param id - if of song
* @return true if all done
*/
bool unSelect(int id);
/**
* @brief getSelected
* @return list of selected songs
*/
QList<int> getSelected();
/**
* @brief isSelected
* @param id - id of checked song
* @return true if song selected
*/
bool isSelected(int id);
};
#endif // PLAYLISTMODEL_H

View File

@ -5,6 +5,7 @@ namespace syncLib{
static const QStringList ValidSongs = {".mp3", ".wav", ".ogg"};
SongHeader::SongHeader()
{
this->isSelected = false;
this->id = -1;
this->name = "";
this->size = 0;

View File

@ -26,6 +26,7 @@ struct Syncer
class SongHeader{
public:
bool isSelected;
int id;
QString name;
int size;
@ -36,6 +37,14 @@ public:
bool isNameValid() const;
virtual bool isValid() const;
virtual ~SongHeader();
/**
* serialize data:
* id,
* size,
* and,
* name
*/
friend QDataStream& operator << (QDataStream& stream, const SongHeader& song);
friend QDataStream& operator >> (QDataStream& stream, SongHeader& song);
};