File indexing completed on 2024-05-12 15:27:45

0001 /***************************************************************************
0002     File                 : BinaryOptionsWidget.cpp
0003     Project              : LabPlot
0004     Description          : widget providing options for the import of binary data
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2009-2017 by Stefan Gerlach (stefan.gerlach@uni.kn)
0007     Copyright            : (C) 2009 by Alexander Semke (alexander.semke@web.de)
0008 
0009  ***************************************************************************/
0010 
0011 /***************************************************************************
0012  *                                                                         *
0013  *  This program is free software; you can redistribute it and/or modify   *
0014  *  it under the terms of the GNU General Public License as published by   *
0015  *  the Free Software Foundation; either version 2 of the License, or      *
0016  *  (at your option) any later version.                                    *
0017  *                                                                         *
0018  *  This program is distributed in the hope that it will be useful,        *
0019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0021  *  GNU General Public License for more details.                           *
0022  *                                                                         *
0023  *   You should have received a copy of the GNU General Public License     *
0024  *   along with this program; if not, write to the Free Software           *
0025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0026  *   Boston, MA  02110-1301  USA                                           *
0027  *                                                                         *
0028  ***************************************************************************/
0029 #include "BinaryOptionsWidget.h"
0030 #include "backend/datasources/filters/BinaryFilter.h"
0031 
0032 #include <KSharedConfig>
0033 #include <KConfigGroup>
0034 
0035 /*!
0036     \class BinaryOptionsWidget
0037     \brief Widget providing options for the import of binary data
0038 
0039     \ingroup kdefrontend
0040 */
0041 
0042 BinaryOptionsWidget::BinaryOptionsWidget(QWidget* parent) : QWidget(parent) {
0043     ui.setupUi(parent);
0044 
0045     ui.cbDataType->addItems(BinaryFilter::dataTypes());
0046     ui.cbByteOrder->addItem(i18n("Little endian"), QDataStream::LittleEndian);
0047     ui.cbByteOrder->addItem(i18n("Big endian"), QDataStream::BigEndian);
0048 
0049     const QString textDataTypeShort = i18n("This option determines the data type that the imported data while converting to numbers.");
0050 
0051     ui.lDataType->setToolTip(textDataTypeShort);
0052     ui.lDataType->setWhatsThis(textDataTypeShort);
0053     ui.cbDataType->setToolTip(textDataTypeShort);
0054     ui.cbDataType->setWhatsThis(textDataTypeShort);
0055 
0056     const QString textByteOrderShort = i18n("This option determines the byte order of the imported data when converting to numbers.");
0057     const QString textByteOrder = textByteOrderShort + "<br><br>" + i18n(
0058     "<table>"
0059     "<tr><td>little endian</td><td>typical byte order (endianness) on Intel x86 processors.</td></tr>"
0060     "<tr><td>big endian</td><td>typical byte order on Mainframes (IBM) and SPARC/PowerPC/Motorola processors.</td></tr>"
0061     "</table>");
0062 
0063     ui.lByteOrder->setToolTip(textByteOrderShort);
0064     ui.lByteOrder->setWhatsThis(textByteOrder);
0065     ui.cbByteOrder->setToolTip(textByteOrderShort);
0066     ui.cbByteOrder->setWhatsThis(textByteOrder);
0067 }
0068 
0069 void BinaryOptionsWidget::applyFilterSettings(BinaryFilter* filter) const {
0070     Q_ASSERT(filter);
0071 
0072     filter->setVectors( ui.niVectors->value() );
0073     filter->setDataType( (BinaryFilter::DataType)ui.cbDataType->currentIndex() );
0074     filter->setByteOrder(static_cast<QDataStream::ByteOrder>(ui.cbByteOrder->currentData().toInt()));
0075     filter->setSkipBytes(ui.sbSkipBytes->value());
0076     filter->setSkipStartBytes(ui.sbSkipStartBytes->value());
0077     filter->setCreateIndexEnabled( ui.chbCreateIndex->isChecked() );
0078 }
0079 
0080 void BinaryOptionsWidget::loadSettings() const {
0081     KConfigGroup conf(KSharedConfig::openConfig(), "ImportBinary");
0082 
0083     ui.niVectors->setValue(conf.readEntry("Vectors", "2").toInt());
0084     ui.cbDataType->setCurrentIndex(conf.readEntry("DataType", 0));
0085     ui.cbByteOrder->setCurrentIndex(conf.readEntry("ByteOrder", 0));
0086     ui.sbSkipStartBytes->setValue(conf.readEntry("SkipStartBytes", 0));
0087     ui.sbSkipBytes->setValue(conf.readEntry("SkipBytes", 0));
0088     ui.chbCreateIndex->setChecked(conf.readEntry("CreateIndex", false));
0089 }
0090 
0091 void BinaryOptionsWidget::saveSettings() {
0092     KConfigGroup conf(KSharedConfig::openConfig(), "ImportBinary");
0093 
0094     conf.writeEntry("Vectors", ui.niVectors->value());
0095     conf.writeEntry("ByteOrder", ui.cbByteOrder->currentIndex());
0096     conf.writeEntry("DataType", ui.cbDataType->currentIndex());
0097     conf.writeEntry("SkipStartBytes", ui.sbSkipStartBytes->value());
0098     conf.writeEntry("SkipBytes", ui.sbSkipBytes->value());
0099     conf.writeEntry("CreateIndex", ui.chbCreateIndex->isChecked());
0100 }