-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
369 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
INCLUDEPATH += \ | ||
$$PWD/cpp/ | ||
|
||
HEADERS += \ | ||
$$PWD/cpp/JsonFormat.h | ||
|
||
SOURCES += \ | ||
$$PWD/cpp/JsonFormat.cpp | ||
|
||
RESOURCES += \ | ||
$$PWD/qml/JsonFormat.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "JsonFormat.h" | ||
|
||
// Qt lib import | ||
#include <QClipboard> | ||
#include <QApplication> | ||
#include <QJsonObject> | ||
#include <QJsonDocument> | ||
|
||
// JQToolsLibrary import | ||
#include "JQToolsLibrary.hpp" | ||
|
||
using namespace JsonFormat; | ||
|
||
bool Manage::check(const QString &string) | ||
{ | ||
return !QJsonDocument::fromJson( string.toUtf8() ).isNull(); | ||
} | ||
|
||
QString Manage::format(const QString &string, const bool &compact) | ||
{ | ||
return QJsonDocument::fromJson( string.toUtf8() ).toJson( ( compact ) ? ( QJsonDocument::Compact ) : ( QJsonDocument::Indented ) ); | ||
} | ||
|
||
QString Manage::clipboardText() | ||
{ | ||
return qApp->clipboard()->text(); | ||
} | ||
|
||
void Manage::setClipboardText(const QString &string) | ||
{ | ||
qApp->clipboard()->setText( string ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef __JsonFormat_h__ | ||
#define __JsonFormat_h__ | ||
|
||
// Qt lib import | ||
#include <QObject> | ||
|
||
#define JSONFORMAT_INITIALIZA \ | ||
{ \ | ||
qmlRegisterType<JsonFormat::Manage>("JsonFormat", 1, 0, "JsonFormatManage"); \ | ||
} | ||
|
||
namespace JsonFormat | ||
{ | ||
|
||
class Manage: public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(Manage) | ||
|
||
public: | ||
Manage() = default; | ||
|
||
~Manage() = default; | ||
|
||
public slots: | ||
bool check(const QString &string); | ||
|
||
QString format(const QString &string, const bool &compact); | ||
|
||
QString clipboardText(); | ||
|
||
void setClipboardText(const QString &string); | ||
}; | ||
|
||
} | ||
|
||
#endif//__JsonFormat_h__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import QtQuick 2.5 | ||
import QtQuick.Controls 1.4 | ||
import QtGraphicalEffects 1.0 | ||
import "qrc:/MaterialUI/Interface/" | ||
import JsonFormat 1.0 | ||
|
||
Item { | ||
id: jsonFormat | ||
width: 620 | ||
height: 540 | ||
|
||
function format() { | ||
if ( !jsonFormatManage.check( textFieldForSource.text ) ) | ||
{ | ||
materialUI.showSnackbarMessage( "无效的JSON字符串" ); | ||
return false; | ||
} | ||
|
||
textFieldForSource.text = jsonFormatManage.format( textFieldForSource.text, checkBoxForCompact.checked ); | ||
return true; | ||
} | ||
|
||
JsonFormatManage { | ||
id: jsonFormatManage | ||
} | ||
|
||
MaterialButton { | ||
x: 386 | ||
text: "格式化" | ||
anchors.horizontalCenterOffset: 0 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
anchors.top: parent.top | ||
anchors.topMargin: 39 | ||
|
||
onClicked: jsonFormat.format(); | ||
} | ||
|
||
MaterialButton { | ||
x: 386 | ||
text: "处理剪切板内容" | ||
anchors.horizontalCenterOffset: 172 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
anchors.top: parent.top | ||
anchors.topMargin: 39 | ||
|
||
onClicked: { | ||
textFieldForSource.text = jsonFormatManage.clipboardText(); | ||
if ( !jsonFormat.format() ) { return; } | ||
jsonFormatManage.setClipboardText( textFieldForSource.text ); | ||
materialUI.showSnackbarMessage( "格式化后的JSON字符串已经复制到了剪切板" ); | ||
} | ||
} | ||
|
||
MaterialCheckBox { | ||
id: checkBoxForCompact | ||
x: 192 | ||
text: "压缩模式" | ||
anchors.horizontalCenterOffset: -147 | ||
anchors.top: parent.top | ||
anchors.topMargin: 30 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
} | ||
|
||
RectangularGlow { | ||
z: -1 | ||
anchors.fill: itemForSource | ||
glowRadius: 6 | ||
spread: 0.22 | ||
color: "#20000000" | ||
} | ||
|
||
Item { | ||
id: itemForSource | ||
anchors.left: parent.left | ||
anchors.leftMargin: 10 | ||
anchors.bottom: parent.bottom | ||
anchors.bottomMargin: 10 | ||
width: jsonFormat.width - 20 | ||
height: jsonFormat.height - 110 | ||
clip: true | ||
|
||
Rectangle { | ||
anchors.fill: parent | ||
color: "#ffffff" | ||
} | ||
|
||
TextEdit { | ||
id: textFieldForSource | ||
x: 5 | ||
y: 5 | ||
width: parent.width - 10 | ||
height: parent.height - 10 | ||
wrapMode: TextInput.WrapAnywhere | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/JsonFormat"> | ||
<file>JsonFormat.qml</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.