mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
chore: update files of project
This commit is contained in:
parent
95667e2f1e
commit
3ea285bbbe
@ -27,13 +27,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QTextDocument>
|
||||
#include <QTranslator>
|
||||
#ifdef X_TOOLS_IMPORT_MODULE_QML
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||
#include <QQuickTextDocument>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "xToolsDataStructure.h"
|
||||
#include "xToolsSettings.h"
|
||||
|
||||
xToolsApplication::xToolsApplication(int argc, char *argv[])
|
||||
@ -183,93 +177,36 @@ QIcon xToolsApplication::cookedIcon(const QIcon &icon)
|
||||
QMainWindow *xToolsApplication::mainWindow()
|
||||
{
|
||||
for (const auto& it : qobject_cast<QApplication*>(qApp)->topLevelWidgets()) {
|
||||
auto w = qobject_cast<QMainWindow*>(it);
|
||||
if (w) {
|
||||
return w;
|
||||
auto mainWindow = qobject_cast<QMainWindow*>(it);
|
||||
if (mainWindow) {
|
||||
return mainWindow;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void xToolsApplication::setMaximumBlockCount(QVariant doc, int maximum)
|
||||
QString xToolsApplication::clipboardText()
|
||||
{
|
||||
auto obj = doc.value<QObject *>();
|
||||
if (obj) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||
#ifdef X_TOOLS_IMPORT_MODULE_QML
|
||||
auto quickTextDoc = qobject_cast<QQuickTextDocument *>(obj);
|
||||
if (quickTextDoc) {
|
||||
auto textDoc = quickTextDoc->textDocument();
|
||||
textDoc->setMaximumBlockCount(maximum);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(doc)
|
||||
Q_UNUSED(maximum)
|
||||
#endif
|
||||
#else
|
||||
Q_UNUSED(doc)
|
||||
Q_UNUSED(maximum)
|
||||
#endif
|
||||
}
|
||||
return QGuiApplication::clipboard()->text();
|
||||
}
|
||||
|
||||
void xToolsApplication::setClipboardText(const QString &text)
|
||||
{
|
||||
QGuiApplication::clipboard()->setText(text);
|
||||
}
|
||||
|
||||
QString xToolsApplication::arrayToString(const QByteArray &array, int format)
|
||||
{
|
||||
auto cookedArray = [](const QByteArray &array, int base, int len) -> QString {
|
||||
QString str, numStr;
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
if (base == 10 || base == 8) {
|
||||
numStr = QString::number(array.at(i), base);
|
||||
str.append(QString("%1 ").arg(numStr));
|
||||
} else {
|
||||
numStr = QString::number(quint8(array.at(i)), base);
|
||||
str.append(QString("%1 ").arg(numStr, len, '0'));
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
if (xToolsDataStructure::TextFormatBin == format) {
|
||||
return cookedArray(array, 2, 8);
|
||||
} else if (xToolsDataStructure::TextFormatOct == format) {
|
||||
return cookedArray(array, 8, 3);
|
||||
} else if (xToolsDataStructure::TextFormatDec == format) {
|
||||
return cookedArray(array, 10, 3);
|
||||
} else if (xToolsDataStructure::TextFormatHex == format) {
|
||||
return cookedArray(array, 16, 2);
|
||||
} else if (xToolsDataStructure::TextFormatAscii == format) {
|
||||
return QString::fromLatin1(array);
|
||||
} else {
|
||||
return QString::fromUtf8(array);
|
||||
}
|
||||
}
|
||||
|
||||
QString xToolsApplication::dateTimeString(const QString &format)
|
||||
{
|
||||
return QDateTime::currentDateTime().toString(format);
|
||||
}
|
||||
|
||||
QString xToolsApplication::cookedFileName(const QString &fileName)
|
||||
{
|
||||
QString cookedFileName = fileName;
|
||||
#ifdef Q_OS_WIN
|
||||
cookedFileName = cookedFileName.remove("file:///");
|
||||
#endif
|
||||
|
||||
return cookedFileName;
|
||||
}
|
||||
|
||||
QString xToolsApplication::string2hexString(const QString &str)
|
||||
QString xToolsApplication::stringToHexString(const QString &str)
|
||||
{
|
||||
return QString::fromLatin1(str.toUtf8().toHex());
|
||||
}
|
||||
|
||||
QString xToolsApplication::hexString2String(const QString &str)
|
||||
QString xToolsApplication::hexStringToString(const QString &str)
|
||||
{
|
||||
QByteArray arr = QByteArray::fromHex(str.toUtf8());
|
||||
return QString::fromUtf8(arr);
|
||||
|
||||
@ -40,13 +40,12 @@ public:
|
||||
static QIcon cookedIcon(const QIcon &icon);
|
||||
static QMainWindow *mainWindow();
|
||||
|
||||
Q_INVOKABLE static void setMaximumBlockCount(QVariant doc, int maximum);
|
||||
Q_INVOKABLE static QString clipboardText();
|
||||
Q_INVOKABLE static void setClipboardText(const QString &text);
|
||||
Q_INVOKABLE static QString arrayToString(const QByteArray &array, int format);
|
||||
|
||||
Q_INVOKABLE static QString dateTimeString(const QString &format);
|
||||
Q_INVOKABLE static QString cookedFileName(const QString &fileName);
|
||||
Q_INVOKABLE static QString string2hexString(const QString &str);
|
||||
Q_INVOKABLE static QString hexString2String(const QString &str);
|
||||
Q_INVOKABLE static QString stringToHexString(const QString &str);
|
||||
Q_INVOKABLE static QString hexStringToString(const QString &str);
|
||||
Q_INVOKABLE static QString buildDateTime(const QString &format);
|
||||
Q_INVOKABLE static QString systemDateFormat();
|
||||
Q_INVOKABLE static QString systemTimeFormat();
|
||||
|
||||
@ -240,7 +240,7 @@ QString xToolsToolBoxUi::dateTimeFormat()
|
||||
void xToolsToolBoxUi::output2ui(const QByteArray& bytes, const QString& flag, bool isRx)
|
||||
{
|
||||
int format = ui->comboBoxOutputFormat->currentData().toInt();
|
||||
QString str = xToolsApplication::arrayToString(bytes, format);
|
||||
QString str = xToolsDataStructure::byteArrayToString(bytes, format);
|
||||
|
||||
if (!str.contains(m_outputMenu->filter())) {
|
||||
return;
|
||||
@ -312,7 +312,7 @@ void xToolsToolBoxUi::setDefaultText()
|
||||
{
|
||||
QByteArray ba("(null)");
|
||||
int format = ui->comboBoxInputFormat->currentData().toInt();
|
||||
QString str = xToolsApplication::arrayToString(ba, format);
|
||||
QString str = xToolsDataStructure::byteArrayToString(ba, format);
|
||||
ui->comboBoxInputText->setCurrentText(str);
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#include <QTextStream>
|
||||
#include <Qt>
|
||||
|
||||
#include "xToolsApplication.h"
|
||||
#include "xToolsDataStructure.h"
|
||||
|
||||
xToolsStorerTool::xToolsStorerTool(QObject *parent)
|
||||
: xToolsBaseTool{parent}
|
||||
@ -166,8 +166,7 @@ void xToolsStorerTool::write2file()
|
||||
this->mParametersMutex.lock();
|
||||
int format = this->mParameters.format;
|
||||
this->mParametersMutex.unlock();
|
||||
auto str = xToolsApplication::arrayToString(bytes, format);
|
||||
|
||||
auto str = xToolsDataStructure::byteArrayToString(bytes, format);
|
||||
QString dtStr;
|
||||
auto dt = QDateTime::currentDateTime();
|
||||
if (mParameters.saveDate && mParameters.saveTime) {
|
||||
@ -189,6 +188,7 @@ void xToolsStorerTool::write2file()
|
||||
}
|
||||
}
|
||||
}
|
||||
outStream << dtStr << str << "\n";
|
||||
}
|
||||
file.close();
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user