Changeset - 4b3919970a41
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-01-03 06:46:44
hy@ozderya.net
added channel info constructor and new 32 color palette
2 files changed with 52 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -17,31 +17,64 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "channelinfomodel.h"
 
#include "setting_defines.h"
 

	
 
const QColor colors[8] =
 
#define NUMOF_COLORS  (32)
 

	
 
const QColor colors[NUMOF_COLORS] =
 
{
 
    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),
 
    QColor(219,136,44)
 
    QColor("#ff0056"),
 
    QColor("#7e2dd2"),
 
    QColor("#00ae7e"),
 
    QColor("#fe8900"),
 
    QColor("#ff937e"),
 
    QColor("#6a826c"),
 
    QColor("#ff029d"),
 
    QColor("#00b917"),
 
    QColor("#7a4782"),
 
    QColor("#85a900"),
 
    QColor("#a42400"),
 
    QColor("#683d3b"),
 
    QColor("#bdc6ff"),
 
    QColor("#263400"),
 
    QColor("#bdd393"),
 
    QColor("#d5ff00"),
 
    QColor("#9e008e"),
 
    QColor("#001544"),
 
    QColor("#c28c9f"),
 
    QColor("#ff74a3"),
 
    QColor("#01d0ff"),
 
    QColor("#004754"),
 
    QColor("#e56ffe"),
 
    QColor("#788231"),
 
    QColor("#0e4ca1"),
 
    QColor("#91d0cb"),
 
    QColor("#be9970"),
 
    QColor("#968ae8"),
 
    QColor("#bb8800"),
 
    QColor("#43002c"),
 
    QColor("#deff74"),
 
    QColor("#00ffc6")
 
};
 

	
 
ChannelInfoModel::ChannelInfoModel(unsigned numberOfChannels, QObject* parent) :
 
    QAbstractTableModel(parent)
 
{
 
    _numOfChannels = 0;
 
    setNumOfChannels(numberOfChannels);
 
}
 

	
 
ChannelInfoModel::ChannelInfo::ChannelInfo(unsigned index)
 
{
 
    name = tr("Channel %1").arg(index + 1);
 
    visibility = true;
 
    color = colors[index % NUMOF_COLORS];
 
}
 

	
 
int ChannelInfoModel::rowCount(const QModelIndex &parent) const
 
{
 
    return _numOfChannels;
 
}
 

	
 
int ChannelInfoModel::columnCount(const QModelIndex & parent) const
 
@@ -182,13 +215,13 @@ void ChannelInfoModel::setNumOfChannels(
 
    // we create channel info but never remove channel info to
 
    // remember user entered info
 
    if ((int) number > infos.length())
 
    {
 
        for (unsigned ci = _numOfChannels; ci < number; ci++)
 
        {
 
            infos.append({QString("Channel %1").arg(ci+1), true, colors[ci % 8]});
 
            infos.append(ChannelInfo(ci));
 
        }
 
    }
 

	
 
    // make sure newly available channels are visible, we don't
 
    // remember visibility option intentionally so that user doesn't
 
    // get confused
 
@@ -214,33 +247,33 @@ void ChannelInfoModel::setNumOfChannels(
 

	
 
void ChannelInfoModel::resetInfos()
 
{
 
    beginResetModel();
 
    for (unsigned ci = 0; (int) ci < infos.length(); ci++)
 
    {
 
        infos[ci] = {QString("Channel %1").arg(ci+1), true, colors[ci % 8]};
 
        infos[ci] = ChannelInfo(ci);
 
    }
 
    endResetModel();
 
}
 

	
 
void ChannelInfoModel::resetNames()
 
{
 
    beginResetModel();
 
    for (unsigned ci = 0; (int) ci < infos.length(); ci++)
 
    {
 
        infos[ci].name = QString("Channel %1").arg(ci+1);
 
        infos[ci].name = ChannelInfo(ci).name;
 
    }
 
    endResetModel();
 
}
 

	
 
void ChannelInfoModel::resetColors()
 
{
 
    beginResetModel();
 
    for (unsigned ci = 0; (int) ci < infos.length(); ci++)
 
    {
 
        infos[ci].color = colors[ci % 8];
 
        infos[ci].color = ChannelInfo(ci).color;
 
    }
 
    endResetModel();
 
}
 

	
 
void ChannelInfoModel::resetVisibility()
 
{
 
@@ -276,16 +309,15 @@ void ChannelInfoModel::loadSettings(QSet
 
    unsigned size = settings->beginReadArray(SG_Channels_Channel);
 

	
 
    for (unsigned ci = 0; ci < size; ci++)
 
    {
 
        settings->setArrayIndex(ci);
 

	
 
        ChannelInfo chanInfo;
 
        chanInfo.name       = settings->value(SG_Channels_Name,
 
                                              QString(tr("Channel %1")).arg(ci+1)).toString();
 
        chanInfo.color      = settings->value(SG_Channels_Color, colors[ci % 8]).value<QColor>();
 
        ChannelInfo chanInfo(ci);
 
        chanInfo.name       = settings->value(SG_Channels_Name, chanInfo.name).toString();
 
        chanInfo.color      = settings->value(SG_Channels_Color, chanInfo.color).value<QColor>();
 
        chanInfo.visibility = settings->value(SG_Channels_Visible, true).toBool();
 

	
 
        if ((int) ci < infos.size())
 
        {
 
            infos[ci] = chanInfo;
 

	
src/channelinfomodel.h
Show inline comments
 
@@ -62,21 +62,23 @@ public slots:
 
    /// reset visibility
 
    void resetVisibility();
 

	
 
private:
 
    struct ChannelInfo
 
    {
 
        explicit ChannelInfo(unsigned index);
 

	
 
        QString name;
 
        bool visibility;
 
        QColor color;
 
    };
 

	
 
    unsigned _numOfChannels;     ///< @note this is not necessarily the length of `infos`
 

	
 
    /**
 
     * Channel info is added here but never removed so that we can
 
     * remember user entered names.
 
     * remember user entered info (names, colors etc.).
 
     */
 
    QList<ChannelInfo> infos;
 
};
 

	
 
#endif // CHANNELINFOMODEL_H
0 comments (0 inline, 0 general)