radioapp/radiouiengine/inc/radiostationmodel.h
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 19 afea38384506
parent 32 189d20c34778
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    18 #ifndef RADIOSTATIONMODEL_H_
    18 #ifndef RADIOSTATIONMODEL_H_
    19 #define RADIOSTATIONMODEL_H_
    19 #define RADIOSTATIONMODEL_H_
    20 
    20 
    21 // System includes
    21 // System includes
    22 #include <QAbstractListModel>
    22 #include <QAbstractListModel>
       
    23 #include <QScopedPointer>
    23 #include <QMap>
    24 #include <QMap>
    24 
    25 
    25 // User includes
    26 // User includes
    26 #include "radio_global.h"
    27 #include "radio_global.h"
    27 #include "radiouiengineexport.h"
    28 #include "radiouiengineexport.h"
    37 class QIcon;
    38 class QIcon;
    38 
    39 
    39 // Constants
    40 // Constants
    40 typedef QMap<uint,RadioStation> Stations;
    41 typedef QMap<uint,RadioStation> Stations;
    41 
    42 
       
    43 namespace FindCriteria
       
    44 {
       
    45     enum Criteria
       
    46     {
       
    47         OnlySavedStations,
       
    48         IncludeManualStation
       
    49     };
       
    50 }
       
    51 
    42 // Class declaration
    52 // Class declaration
    43 class UI_ENGINE_DLL_EXPORT RadioStationModel : public QAbstractListModel
    53 class UI_ENGINE_DLL_EXPORT RadioStationModel : public QAbstractListModel
    44 {
    54 {
    45     Q_OBJECT
    55     Q_OBJECT
    46     Q_DECLARE_PRIVATE_D( d_ptr, RadioStationModel )
    56     Q_DECLARE_PRIVATE_D( d_ptr.data(), RadioStationModel )
    47     Q_DISABLE_COPY( RadioStationModel )
    57     Q_DISABLE_COPY( RadioStationModel )
    48 
    58 
    49 public:
    59 public:
    50 
       
    51     enum RadioRole
       
    52     {
       
    53         RadioStationRole = Qt::UserRole + 1,
       
    54         ToggleFavoriteRole
       
    55     };
       
    56 
    60 
    57     enum DetailFlag
    61     enum DetailFlag
    58     {
    62     {
    59         Minimal     = 1 << 0,
    63         Minimal     = 1 << 0,
    60         ShowIcons   = 1 << 1,
    64         ShowIcons   = 1 << 1,
   100      * The station is returned by value, but it is cheap because it is implicitly shared
   104      * The station is returned by value, but it is cheap because it is implicitly shared
   101      */
   105      */
   102     RadioStation stationAt( int index ) const;
   106     RadioStation stationAt( int index ) const;
   103 
   107 
   104     /*!
   108     /*!
   105      * Functions to find stations by frequency
   109      * Finds a station by frequency
   106      */
   110      */
   107     bool findFrequency( uint frequency, RadioStation& station );
   111     bool findFrequency( uint frequency, RadioStation& station, FindCriteria::Criteria criteria = FindCriteria::OnlySavedStations ) const;
       
   112 
       
   113     /*!
       
   114      * Convenience function to find a radio station.
       
   115      * Internally uses findFrequency() and returns an invalid station if the given frequency is not found
       
   116      */
       
   117     RadioStation findStation( uint frequency, FindCriteria::Criteria criteria = FindCriteria::OnlySavedStations ) const;
   108 
   118 
   109     /*!
   119     /*!
   110      * Functions to find stations by preset index
   120      * Functions to find stations by preset index
   111      */
   121      */
   112     int findPresetIndex( int presetIndex );
   122     int findPresetIndex( int presetIndex );
   114 
   124 
   115     /*!
   125     /*!
   116      * Finds the closest station from the given frequency
   126      * Finds the closest station from the given frequency
   117      */
   127      */
   118     RadioStation findClosest( const uint frequency, StationSkip::Mode mode );
   128     RadioStation findClosest( const uint frequency, StationSkip::Mode mode );
       
   129 
       
   130     /*!
       
   131      * Checks if the model contains the given frequency
       
   132      */
       
   133     bool contains( const uint frequency ) const;
   119 
   134 
   120     /*!
   135     /*!
   121      * Functions to remove stations
   136      * Functions to remove stations
   122      */
   137      */
   123     void removeByFrequency( uint frequency );
   138     void removeByFrequency( uint frequency );
   166     QList<RadioStation> stationsInRange( uint minFrequency, uint maxFrequency );
   181     QList<RadioStation> stationsInRange( uint minFrequency, uint maxFrequency );
   167 
   182 
   168     /*!
   183     /*!
   169      * Returns the model index corresponding to the given frequency
   184      * Returns the model index corresponding to the given frequency
   170      */
   185      */
   171     QModelIndex modelIndexFromFrequency( uint frequency );
   186     int indexFromFrequency( uint frequency );
   172 
   187 
   173 signals:
   188 signals:
   174 
   189 
   175     void stationDataChanged( const RadioStation& station );
   190     void stationDataChanged( const RadioStation& station );
   176     void radioTextReceived( const RadioStation& station );
   191     void radioTextReceived( const RadioStation& station );
   199     /*!
   214     /*!
   200      * Finds an unused preset index
   215      * Finds an unused preset index
   201      */
   216      */
   202     int findUnusedPresetIndex();
   217     int findUnusedPresetIndex();
   203 
   218 
   204     /**
       
   205      * Used by the RDS data setters to find the correct station where the data is set
       
   206      * First tries the currentStation variable and if the frequency doesn't match, finds the right one
       
   207      */
       
   208     RadioStation findCurrentStation( uint frequency );
       
   209 
       
   210 private: // data
   219 private: // data
   211 
   220 
   212     /**
   221     /**
   213      * Unmodifiable pointer to the private implementation
   222      * Unmodifiable pointer to the private implementation
   214      */
   223      */
   215     RadioStationModelPrivate* const d_ptr;
   224     const QScopedPointer<RadioStationModelPrivate> d_ptr;
   216 
   225 
   217 };
   226 };
   218 
   227 
   219 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationModel::Detail )
   228 Q_DECLARE_OPERATORS_FOR_FLAGS( RadioStationModel::Detail )
   220 
   229