Changeset - 6254c449bb19
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-01-02 03:26:52
hy@ozderya.net
save/load all known channel info
4 files changed with 62 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

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

	
 
const QColor colors[8] =
 
{
 
    QColor(237,97,68),
 
    QColor(92,200,96),
 
    QColor(225,98,207),
 
@@ -207,6 +208,58 @@ void ChannelInfoModel::setNumOfChannels(
 
    }
 
    else
 
    {
 
        endRemoveRows();
 
    }
 
}
 

	
 
void ChannelInfoModel::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Channels);
 
    settings->beginWriteArray(SG_Channels_Channel);
 

	
 
    // save all channel information regardless of current number of channels
 
    for (unsigned ci = 0; (int) ci < infos.length(); ci++)
 
    {
 
        settings->setArrayIndex(ci);
 
        settings->setValue(SG_Channels_Name, infos[ci].name);
 
        settings->setValue(SG_Channels_Color, infos[ci].color);
 
        settings->setValue(SG_Channels_Visible, infos[ci].visibility);
 
    }
 

	
 
    settings->endArray();
 
    settings->endGroup();
 
}
 

	
 
void ChannelInfoModel::loadSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Channels);
 
    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>();
 
        chanInfo.visibility = settings->value(SG_Channels_Visible, true).toBool();
 

	
 
        if ((int) ci >= infos.size())
 
        {
 
            infos.append(chanInfo);
 
        }
 
        else
 
        {
 
            infos[ci] = chanInfo;
 

	
 
            auto roles = QVector<int>({
 
                    Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole, Qt::CheckStateRole});
 

	
 
            emit dataChanged(index(ci, 0), index(ci, COLUMN_COUNT-1), roles);
 
        }
 
    }
 

	
 
    settings->endArray();
 
    settings->endGroup();
 
}
src/channelinfomodel.h
Show inline comments
 
@@ -19,12 +19,13 @@
 

	
 
#ifndef CHANNELINFOMODEL_H
 
#define CHANNELINFOMODEL_H
 

	
 
#include <QAbstractTableModel>
 
#include <QColor>
 
#include <QSettings>
 

	
 
class ChannelInfoModel : public QAbstractTableModel
 
{
 
    Q_OBJECT
 

	
 
public:
 
@@ -43,12 +44,16 @@ public:
 
    QVariant      data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
    bool          setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
 
    Qt::ItemFlags flags(const QModelIndex &index) const;
 
    QVariant      headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 

	
 
    void setNumOfChannels(unsigned number);
 
    /// Stores all channel info into a `QSettings`
 
    void saveSettings(QSettings* settings);
 
    /// Loads all channel info from a `QSettings`.
 
    void loadSettings(QSettings* settings);
 

	
 
private:
 
    struct ChannelInfo
 
    {
 
        QString name;
 
        bool visibility;
src/channelmanager.cpp
Show inline comments
 
@@ -166,30 +166,13 @@ void ChannelManager::addChannelData(unsi
 
{
 
    channelBuffer(channel)->addSamples(data, size);
 
}
 

	
 
void ChannelManager::saveSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Channels);
 
    settings->beginWriteArray(SG_Channels_Channel);
 
    for (unsigned i = 0; i < numOfChannels(); i++)
 
    {
 
        settings->setArrayIndex(i);
 
        settings->setValue(SG_Channels_Name, channelName(i));
 
    }
 
    settings->endArray();
 
    settings->endGroup();
 
    _infoModel.saveSettings(settings);
 
}
 

	
 
void ChannelManager::loadSettings(QSettings* settings)
 
{
 
    settings->beginGroup(SettingGroup_Channels);
 
    settings->beginReadArray(SG_Channels_Channel);
 
    for (unsigned i = 0; i < numOfChannels(); i++)
 
    {
 
        settings->setArrayIndex(i);
 
        // TODO: fix load settings
 
        // setChannelName(i, settings->value(SG_Channels_Name, channelName(i)).toString());
 
    }
 
    settings->endArray();
 
    settings->endGroup();
 
    _infoModel.loadSettings(settings);
 
}
src/setting_defines.h
Show inline comments
 
@@ -67,12 +67,14 @@ const char SG_CustomFrame_Endianness[] =
 
const char SG_CustomFrame_Checksum[] = "checksum";
 
const char SG_CustomFrame_DebugMode[] = "debugMode";
 

	
 
// channel manager keys
 
const char SG_Channels_Channel[] = "channel";
 
const char SG_Channels_Name[] = "name";
 
const char SG_Channels_Color[] = "color";
 
const char SG_Channels_Visible[] = "visible";
 

	
 
// plot settings keys
 
const char SG_Plot_NumOfSamples[] = "numOfSamples";
 
const char SG_Plot_AutoScale[] = "autoScale";
 
const char SG_Plot_YMax[] = "yMax";
 
const char SG_Plot_YMin[] = "yMin";
0 comments (0 inline, 0 general)