1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

QQtDictionary添加toCSV,fromCSV支持和添加测试用例qqtdicttest8

This commit is contained in:
tianduanrui 2020-04-07 20:08:10 +08:00
parent 3551340131
commit 7a78c26950
23 changed files with 513 additions and 7 deletions

View File

@ -44,11 +44,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
# -Wdisabled-optimization -Wcast-align -Wcast-qual
#}
contains (DEFINES, QQT_LIBRARY) {
DEFINES += QTCSVLIB_LIBRARY
} else:contains (DEFINES, QQT_STATIC_LIBRARY) {
DEFINES += QTCSVLIB_STATIC_LIBRARY
} else { }
win32 {
contains (DEFINES, QQT_LIBRARY) {
DEFINES += QTCSVLIB_LIBRARY
} else:contains (DEFINES, QQT_STATIC_LIBRARY) {
DEFINES += QTCSVLIB_STATIC_LIBRARY
} else { }
}
include($${PWD}/qtcsvlib_header.pri)
include($${PWD}/qtcsvlib_source.pri)

View File

@ -3,6 +3,8 @@
#include <QtGlobal>
#if defined(Q_OS_WIN)
#ifdef QTCSV_STATIC_LIB
# define QTCSVSHARED_EXPORT
#else
@ -13,4 +15,8 @@
# endif
#endif
#else
# define QTCSVSHARED_EXPORT
#endif
#endif // QTCSV_GLOBAL_H

View File

@ -1,8 +1,6 @@
CONFIG *= qt
QT *= core
!contains(DEFINES, QTCSV_LIBRARY): DEFINES += QTCSV_MAKE_LIB
INCLUDEPATH += $$PWD $$PWD/include
SOURCES += \

View File

@ -22,6 +22,14 @@
#include "inifile.h"
#endif
#ifdef __QTCSVLIB__
#include "qtcsv/reader.h"
#include "qtcsv/writer.h"
#include "qtcsv/stringdata.h"
#endif
#include <QBuffer>
#include <iostream>
using namespace std;
@ -39,6 +47,17 @@ void parseYamlNodeToDictionary ( const YAML::Node& node, QQtDictionary& object )
void packDictionaryToYamlNode ( const QQtDictionary& node, YAML::Node& object );
#endif
#ifdef __QTCSVLIB__
QByteArray toCSV ( const QQtDictionary& dict,
const QString& separator,
const QString& textDelimiter,
const QString& textEncoding );
void fromCSV ( const QByteArray& csv, QQtDictionary& dict,
const QString& separator,
const QString& textDelimiter,
const QString& textEncoding );
#endif
QByteArray toJson ( const QQtDictionary& dict, int indent = 0 );
void fromJson ( const QByteArray& json, QQtDictionary& dict );
void parseJsonValue ( const QJsonValue& value, QQtDictionary& parent );
@ -533,6 +552,24 @@ void QQtDictionary::fromProperties ( const QByteArray& properties )
}
#endif
#ifdef __QTCSVLIB__
QByteArray QQtDictionary::toCSV ( const QString& separator,
const QString& textDelimiter,
const QString& textEncoding
) const
{
return ::toCSV ( *this, separator, textDelimiter, textEncoding );
}
void QQtDictionary::fromCSV ( const QByteArray& csv,
const QString& separator,
const QString& textDelimiter,
const QString& textEncoding )
{
::fromCSV ( csv, *this, separator, textDelimiter, textEncoding );
}
#endif
bool QQtDictionary::operator == ( const QQtDictionary& other ) const
{
if ( m_type == other.getType() &&
@ -1183,6 +1220,71 @@ void packDictionaryToDomNode ( const QQtDictionary& node, QDomNode& result, QDom
}
}
#ifdef __QTCSVLIB__
QByteArray toCSV ( const QQtDictionary& dict,
const QString& separator,
const QString& textDelimiter,
const QString& textEncoding
)
{
QtCSV::StringData strlist0;
for ( int i = 0; i < dict.getList().size(); i++ )
{
const QQtDictionary& v0 = dict.getList() [i];
QStringList strlist1;
for ( int j = 0; j < v0.getList().size(); j++ )
{
const QQtDictionary& v1 = v0.getList() [j];
strlist1.push_back ( v1.getValue().toString() );
}
strlist0.addRow ( strlist1 );
}
QByteArray bytes;
QBuffer buffer ( &bytes );
buffer.open ( QBuffer::WriteOnly );
QTextCodec* codec = QTextCodec::codecForName ( textEncoding.toLocal8Bit() );
bool ret = QtCSV::Writer::write ( buffer, strlist0,
separator, textDelimiter,
QStringList(), QStringList(),
codec );
if ( !ret )
{
pline() << "QtCSV write error.";
}
buffer.close();
return bytes;
}
void fromCSV ( const QByteArray& csv, QQtDictionary& dict,
const QString& separator,
const QString& textDelimiter,
const QString& textEncoding
)
{
QByteArray bytes = csv;
QBuffer buffer ( &bytes );
buffer.open ( QBuffer::ReadOnly );
QTextCodec* codec = QTextCodec::codecForName ( textEncoding.toLocal8Bit() );
QList<QStringList> strlist0 = QtCSV::Reader::readToList ( buffer,
separator, textDelimiter, codec );
buffer.close();
for ( int i = 0; i < strlist0.size(); i++ )
{
const QStringList& strlist1 = strlist0[i];
for ( int j = 0; j < strlist1.size(); j++ )
{
const QString& strlist2 = strlist1[j];
dict[i][j] = strlist2;
}
}
}
#endif
#ifdef __INICONTENTSUPPORT__
QByteArray toIni ( const QQtDictionary& dict )
{

View File

@ -188,12 +188,24 @@ public:
QByteArray toYAML() const;
void fromYAML ( const QByteArray& yaml );
//INI, CONF
QByteArray toINI() const;
void fromINI ( const QByteArray& ini );
QByteArray toProperties() const;
void fromProperties ( const QByteArray& properties );
//QtCSVLib
QByteArray toCSV ( const QString& separator = QString ( "," ),
const QString& textDelimiter = QString ( "\"" ),
const QString& textEncoding = QString ( "UTF-8" )
) const;
void fromCSV ( const QByteArray& csv,
const QString& separator = QString ( "," ),
const QString& textDelimiter = QString ( "\"" ),
const QString& textEncoding = QString ( "UTF-8" )
);
signals:
public slots:

View File

@ -0,0 +1,6 @@
,制造商,型号,说明,价值
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00
1 制造商 型号 说明 价值
2 1997 Ford E350 ac, abs, moon 3000.00
3 1999 Chevy Venture "Extended Edition" 4900.00
4 1999 Chevy Venture "Extended Edition, Very Large" 5000.00
5 1996 Jeep Grand Cherokee MUST SELL! air, moon roof, loaded 4799.00

View File

@ -0,0 +1,4 @@
ggg ;ggg;ggg
gg;gg;gg
;gg;
;你好;
1 ggg ggg ggg
2 gg gg gg
3 gg
4 你好

View File

@ -0,0 +1,24 @@
/*spinbox 抬起样式*/
QTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button {
subcontrol-origin:border;
subcontrol-position:right;
width: 12px;
}
QTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button {
subcontrol-origin:border;
subcontrol-position:left;
width: 12px;
}
/*按钮按下样式*/
QTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{
subcontrol-origin:border;
subcontrol-position:right;
width: 12px;
}
QTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{
subcontrol-position:left;
width: 12px;
}

View File

@ -0,0 +1,89 @@
<?xml version="1.0"?>
<manifest package="org.qtproject.example.qqtdicttest8" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="qqtdicttest8" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="qqtdicttest8" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Application arguments -->
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->
<meta-data android:name="android.app.lib_name" android:value="qqtdicttest8"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so"/>
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroid-bundled.jar"/>
<meta-data android:name="android.app.static_init_classes" android:value=""/>
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
<!-- Splash screen -->
<!-- Background running -->
<!-- Warning: changing this value to true may cause unexpected crashes if the
application still try to draw after
"applicationStateChanged(Qt::ApplicationSuspended)"
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="false"/>
<!-- Background running -->
<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
<!-- auto screen scale factor -->
<!-- extract android style -->
<!-- available android:values :
* full - useful QWidget & Quick Controls 1 apps
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
* none - useful for apps that don't use any of the above Qt modules
-->
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
<!-- extract android style -->
</activity>
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- %%INSERT_PERMISSIONS -->
<!-- %%INSERT_FEATURES -->
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QQtApplication>
int main ( int argc, char* argv[] )
{
QQtApplication a ( argc, argv );
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,56 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qqtdictionary.h>
#include <QBuffer>
MainWindow::MainWindow ( QWidget* parent ) :
QMainWindow ( parent ),
ui ( new Ui::MainWindow )
{
ui->setupUi ( this );
QFile file ( "b.csv" );
file.open ( QFile::ReadOnly );
QByteArray bytes = file.readAll();
ui->plainTextEdit->appendPlainText ( bytes );
file.close();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked ( bool checked )
{
if ( ui->plainTextEdit->toPlainText().isEmpty() )
return;
QQtDictionary dict;
QByteArray bytes = ui->plainTextEdit->toPlainText().toLocal8Bit();
QString seperate = ui->lineEdit->text();
QString delimer = ui->lineEdit_2->text();
QString encoding = ui->lineEdit_3->text();
dict.fromCSV ( bytes, seperate, delimer, encoding );
qDebug() << dict;
for ( int i = 0; i < dict.getList().size(); i++ )
{
qDebug() << dict[i];
}
seperate = ui->lineEdit_11->text();
delimer = ui->lineEdit_21->text();
encoding = ui->lineEdit_31->text();
ui->textBrowser_2->clear();
ui->textBrowser_2->append ( dict.toCSV ( seperate, delimer, encoding ) );
ui->textBrowser->clear();
ui->textBrowser->append ( dict.toJson ( QJsonDocument::Indented ) );
}

View File

@ -0,0 +1,25 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow ( QWidget* parent = 0 );
~MainWindow();
private slots:
void on_pushButton_clicked ( bool checked );
private:
Ui::MainWindow* ui;
};
#endif // MAINWINDOW_H

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>442</height>
</rect>
</property>
<property name="windowTitle">
<string>qqtdicttest8</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_3">
<property name="text">
<string>UTF-8</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="text">
<string>,</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_2">
<property name="text">
<string>&quot;</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="lineEdit_11">
<property name="text">
<string>,</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="QTextBrowser" name="textBrowser_2"/>
</item>
<item row="0" column="1" colspan="2">
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
<item row="6" column="1" colspan="2">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Translate</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="lineEdit_21">
<property name="text">
<string>&quot;</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="lineEdit_31">
<property name="text">
<string>UTF-8</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,70 @@
#-------------------------------------------------
#
# Project created by QtCreator 2018-10-06T08:16:10
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qqtdicttest8
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
include($${PWD}/../../multi-link/add_base_manager.pri)
#-------------------------------------------------
#用户工程配置
#-------------------------------------------------
add_version(1,0,0,0)
add_deploy()
add_deploy_config($${PWD}/AppRoot)
add_dependent_manager(QQt)
system(touch main.cpp)
#-------------------------------------------------
#用户工程配置
#-------------------------------------------------
equals(QSYS_PRIVATE, macOS) {
CONFIG += app_bundle
}
contains(QSYS_PRIVATE, Android|AndroidX86) {
CONFIG += mobility
MOBILITY =
DISTFILES += \
android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
}
message ($${TARGET} config $${CONFIG})
message ($${TARGET} DEFINE $${DEFINES})
message ($${TARGET} prelink $${QMAKE_PRE_LINK})
message ($${TARGET} postlink $${QMAKE_POST_LINK})
add_file(AppRoot/a.csv)
OTHER_FILES += AppRoot/a.csv
OTHER_FILES += AppRoot/b.csv