Changeset - 3455b67378d9
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-01-01 05:05:51
hy@ozderya.net
added color column
1 file changed with 16 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -17,24 +17,25 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "channelinfomodel.h"
 

	
 
#include <QColor>
 
#include <QtDebug>
 

	
 
enum ChannelInfoColumn
 
{
 
    COLUMN_NAME = 0,
 
    COLUMN_VISIBILITY,
 
    COLUMN_COLOR,
 
    COLUMN_COUNT
 
};
 

	
 
const QColor colors[8] =
 
{
 
    QColor(237,97,68),
 
    QColor(92,200,96),
 
    QColor(225,98,207),
 
    QColor(163,195,58),
 
    QColor(148,123,239),
 
    QColor(212,182,52),
 
    QColor(238,82,133),
 
@@ -59,24 +60,28 @@ int ChannelInfoModel::columnCount(const 
 
}
 

	
 
Qt::ItemFlags ChannelInfoModel::flags(const QModelIndex &index) const
 
{
 
    if (index.column() == COLUMN_NAME)
 
    {
 
        return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable;
 
    }
 
    else if (index.column() == COLUMN_VISIBILITY)
 
    {
 
        return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable;
 
    }
 
    else if (index.column() == COLUMN_COLOR)
 
    {
 
        return Qt::ItemIsEnabled | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable;
 
    }
 

	
 
    return Qt::NoItemFlags;
 
}
 

	
 
QVariant ChannelInfoModel::data(const QModelIndex &index, int role) const
 
{
 
    if (index.row() >= (int) _numOfChannels)
 
    {
 
        return QVariant();
 
    }
 

	
 
    if (index.column() == COLUMN_NAME)
 
@@ -90,42 +95,53 @@ QVariant ChannelInfoModel::data(const QM
 
            // TODO: support more colors than 8
 
            return colors[index.row() % 8];
 
        }
 
    }
 
    else if (index.column() == COLUMN_VISIBILITY)
 
    {
 
        if (role == Qt::CheckStateRole)
 
        {
 
            bool visible = infos[index.row()].visibility;
 
            return visible ? Qt::Checked : Qt::Unchecked;
 
        }
 
    }
 
    else if (index.column() == COLUMN_COLOR)
 
    {
 
        if (role == Qt::ForegroundRole || role == Qt::BackgroundRole)
 
        {
 
            return colors[index.row() % 8];
 
        }
 
    }
 

	
 
    return QVariant();
 
}
 

	
 
QVariant ChannelInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
 
{
 
    if (orientation == Qt::Horizontal)
 
    {
 
        if (role == Qt::DisplayRole)
 
        {
 
            if (section == COLUMN_NAME)
 
            {
 
                return tr("Channel");
 
            }
 
            else if (section == COLUMN_VISIBILITY)
 
            {
 
                return tr("Visible");
 
            }
 
            else if (section == COLUMN_COLOR)
 
            {
 
                return tr("Color");
 
            }
 
        }
 
    }
 
    else                        // vertical
 
    {
 
        if (section < (int) _numOfChannels && role == Qt::DisplayRole)
 
        {
 
            return QString::number(section + 1);
 
        }
 
    }
 

	
 
    return QVariant();
 
}
0 comments (0 inline, 0 general)