增加了界面

LAMPCAE-dev
chenzenghui 2025-06-26 17:53:44 +08:00
parent f7bdcc314f
commit f7d36e4309
9 changed files with 1166 additions and 182 deletions

View File

@ -84,6 +84,11 @@ add_library(PluginRCSDBManager
${SOURCES} ${SOURCES}
RCSDBManagerClass.cpp RCSDBManagerClass.cpp
RCSDBManagerClass.h RCSDBManagerClass.h
RCSDBQueryDialog.cpp
RCSDBQueryDialog.h
RCSDBQueryDialog.ui
QueryDataTableModel.cpp
QueryDataTableModel.h
) )

View File

@ -0,0 +1,401 @@
//
// Created by 30453 on 25-6-26.
//
#include <QColor>
#include <QFile>
#include <QTextStream>
#include <stdlib.h>
#include <stdio.h>
#include <QRegularExpression>
#include <QDebug>
#include "QueryDataTableModel.h"
#include "Settings/BusAPI.h"
namespace RCSDBManagerTool {
QueryDataTableModel::QueryDataTableModel(QObject* parent)
: QAbstractTableModel(parent)
{
}
QueryDataTableModel::~QueryDataTableModel() {}
void QueryDataTableModel::loadProjectDescDataSet(std::vector<ProjectDesc> projectdescSets) {
QStringList colnames;
QVector<QVector<QVariant>> datamap(0);
QStringList rowIDlist;
bool hascolnames = true;
colnames.append(u8"ProjectID");
colnames.append(u8"projectname");
colnames.append(u8"desc");
colnames.append(u8"projectFolder");
size_t rowid = 0;
for (int64_t i=0;i<projectdescSets.size();i++) {
QVector<QVariant> mapline(colnames.count()); // 单行数据
mapline[0]=projectdescSets[i].projectID;
mapline[1]=projectdescSets[i].projectName;
mapline[2]=projectdescSets[i].projectDesc;
mapline[3]=projectdescSets[i].projectFolder;
datamap.append(mapline);
rowIDlist.append(QString::number(rowid));
rowid = rowid + 1;
}
this->SetData(datamap, colnames, rowIDlist);
}
void QueryDataTableModel::loadRCSRecordDataSet(std::vector<RCSRecord> RCSRecordSets) {
QStringList colnames;
QVector<QVector<QVariant>> datamap(0);
QStringList rowIDlist;
bool hascolnames = true;
colnames.append(u8"ProjectID");
colnames.append(u8"freq");
colnames.append(u8"azimuthAngle");
colnames.append(u8"incidentAngle");
colnames.append(u8"TransPolarAngle");
colnames.append(u8"H_E_re");
colnames.append(u8"H_E_im");
colnames.append(u8"V_E_re");
colnames.append(u8"V_E_im");
colnames.append(u8"RCS_H");
colnames.append(u8"RCS_V");
size_t rowid = 0;
for (int64_t i=0;i<RCSRecordSets.size();i++) {
QVector<QVariant> mapline(colnames.count()); // 单行数据
mapline[0]=RCSRecordSets[i].projectID;
mapline[1]=RCSRecordSets[i].frequency;
mapline[2]=RCSRecordSets[i].phi;
mapline[3]=RCSRecordSets[i].theta;
mapline[4]=RCSRecordSets[i].TransPolar;
mapline[5]=RCSRecordSets[i].reEphi;
mapline[6]=RCSRecordSets[i].imEphi;
mapline[7]=RCSRecordSets[i].reEtheta;
mapline[8]=RCSRecordSets[i].imEtheta;
mapline[9]=RCSRecordSets[i].RCS_Phi;
mapline[10]=RCSRecordSets[i].RCS_Theta;
datamap.append(mapline);
rowIDlist.append(QString::number(rowid));
rowid = rowid + 1;
}
this->SetData(datamap, colnames, rowIDlist);
}
void QueryDataTableModel::saveFilePath()
{
QString csvpath=QFileDialog::getSaveFileName(nullptr,u8"导出为csv",
QFileInfo(Setting::BusAPI::instance()->getLastSelectPath()).absolutePath(),
u8"csv文件 (*.csv)"
);
this->csvPath=csvpath;
return this->saveCSVFilePath(this->csvPath);
}
void QueryDataTableModel::saveCSVFilePath(QString csvpath)
{
qDebug() << u8"正在保存为 csv文件中";
QFile file(csvpath);
if(file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
QTextStream stream(&file);
// 写入表头
for(const QString& header : this->m_hor_hedlbls) // 写入表头
{
stream << header;
if(&header != &this->m_hor_hedlbls.last()) // 如果不是最后一列,写入逗号
stream << ",";
}
stream << "\n";
// 写入数据
for(int i = 0; i < this->m_vec_hedlbls.count(); i++) {
if(this->isdeletes[i]) {
} else { // 非删除目标
for(int j = 0; j < this->m_hor_hedlbls.count() - 1; j++) {
stream << this->m_data_map[i][j].toString();
stream << ",";
}
stream << this->m_data_map[i][this->m_hor_hedlbls.count() - 1].toString();
stream << "\n";
}
}
file.close();
}
qDebug() << csvpath;
}
QStringList QueryDataTableModel::getColumnNames()
{
return this->m_hor_hedlbls;
}
QStringList QueryDataTableModel::getItemDataByColumn(int colidx)
{
QStringList result;
for(size_t i = 0; i < this->rowCount(); i++) {
result.append(this->m_data_map[i][colidx].toString());
}
return result;
}
QString QueryDataTableModel::getCSVPath()
{
return this->csvPath;
}
int QueryDataTableModel::getColumnIdxByColumName(QString ColumnName)
{
for(int i = 0; i < this->colCount(); i++) {
if(ColumnName == this->m_hor_hedlbls[i]) {
return i;
}
}
return -1;
}
void QueryDataTableModel::SetData(const QVector<QVector<QVariant>>& map, QStringList& colnames,
QStringList& rowIds)
{
beginResetModel();
m_hor_hedlbls = colnames; // 列名
m_data_map = map;
m_vec_hedlbls = rowIds; // 行名
this->colorData =
QVector<QVector<QColor>>(m_vec_hedlbls.count(), QVector<QColor>(m_hor_hedlbls.count()));
// 增加标记
this->isdeletes = QVector<bool>(m_vec_hedlbls.count(), false);
for(int j = 0; j < m_vec_hedlbls.count(); j++) {
this->isdeletes[j] = false;
}
for(int i = 0; i < m_hor_hedlbls.count(); i++) {
for(int j = 0; j < m_vec_hedlbls.count(); j++) {
this->colorData[j][i] = QColor(255, 255, 255);
}
}
endResetModel();
}
void QueryDataTableModel::setHignlightIndex(QVector<QPair<int, int>> vec_index)
{
beginResetModel();
m_highlight_indexs = vec_index;
endResetModel();
}
Qt::ItemFlags QueryDataTableModel::flags(const QModelIndex& index) const
{
Qt::ItemFlags flags = QAbstractItemModel::flags(index);
flags |= Qt::ItemIsEditable;
return flags;
}
QVariant QueryDataTableModel::data(const QModelIndex& _index, int role) const
{
if(role == Qt::DisplayRole || role == Qt::EditRole) {
return this->m_data_map[_index.row()][_index.column()];
} else if(role == Qt::TextAlignmentRole)
return Qt::AlignCenter; // 文字居中
else if(role == Qt::BackgroundColorRole) // 设置背景色
{
if(m_highlight_indexs.contains(qMakePair<int, int>(_index.row(), _index.column()))) {
return QColor(230, 247, 255);
} else {
return this->colorData[_index.row()][_index.column()];
}
}
// else if(role == Qt::DecorationRole) // 为item添加图标
// {
// return QIcon(":/images/device.svg");
// }
return QVariant();
}
QVariant QueryDataTableModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if(orientation == Qt::Horizontal) {
if(role == Qt::DisplayRole)
return m_hor_hedlbls.at(section);
else
return QVariant();
}
return QAbstractTableModel::headerData(section, orientation, role); // 垂直表头的序号
}
bool QueryDataTableModel::setData(const QModelIndex& _index, const QVariant& value, int role)
{
if(_index.isValid() && role == Qt::EditRole) {
this->isNeedExtendTable(_index.row(), _index.column());
if(this->m_data_map[_index.row()][_index.column()] == value) {
return false;
} else {
}
this->m_data_map[_index.row()][_index.column()] = value;
emit dataChanged(_index, _index);
emit itemChanged(_index, value);
return true;
} else if(role == Qt::BackgroundColorRole) {
this->colorData[_index.row()][_index.column()] = value.value<QColor>();
}
return false;
}
int QueryDataTableModel::rowCount(const QModelIndex& parent) const
{
return this->m_vec_hedlbls.count();
}
int QueryDataTableModel::columnCount(const QModelIndex& parent) const
{
return this->m_hor_hedlbls.count();
}
QString QueryDataTableModel::itemText(int row, int column) const
{
return this->m_data_map[row][column].toString();
}
QString QueryDataTableModel::itemText(const QModelIndex& index) const
{
return this->m_data_map[index.row()][index.column()].toString();
}
void QueryDataTableModel::setItemText(const QModelIndex& index, const QString& str)
{
this->isNeedExtendTable(index.row(), index.column());
this->m_data_map[index.row()][index.column()] = str;
}
void QueryDataTableModel::setItemText(int row, int column, const QString& str)
{
this->isNeedExtendTable(row, column);
this->m_data_map[row][column] = str;
}
QVariant QueryDataTableModel::ItemData(const QModelIndex& index) const
{
if(index.row() >= this->m_data_map.count()
|| index.column() >= this->m_data_map[index.row()].count()) {
return QVariant();
}
return this->m_data_map[index.row()][index.column()];
}
QVariant QueryDataTableModel::ItemData(int row, int column) const
{
if(row >= this->m_data_map.count() || column >= this->m_data_map[row].count()) {
return this->m_data_map[row][column];
} else {
return QVariant();
}
}
void QueryDataTableModel::SetItemData(const QModelIndex& index, const QVariant& data)
{
this->isNeedExtendTable(index.row(), index.column());
this->m_data_map[index.row()][index.column()] = data;
}
void QueryDataTableModel::SetItemData(int row, int column, const QVariant& data)
{
this->isNeedExtendTable(row, column);
this->m_data_map[row][column] = data;
}
size_t QueryDataTableModel::rowCount()
{
return this->m_data_map.count();
}
size_t QueryDataTableModel::colCount()
{
return this->m_vec_hedlbls.count();
}
void QueryDataTableModel::isNeedExtendTable(size_t row, size_t column)
{
size_t max_colnum = this->m_hor_hedlbls.count() - 1 < column
? column + 1
: this->m_hor_hedlbls.count(); // 判断是否扩展列名
if(this->m_hor_hedlbls.count() <= column) {
for(int i = this->m_hor_hedlbls.count(); i <= column; i++) {
this->m_hor_hedlbls.append(QString::number(i));
}
}
if(0 > row || column < 0) {
return;
} else if(row > this->m_vec_hedlbls.count() - 1 || column > this->m_hor_hedlbls.count() - 1) {
for(int i = 0; i <= row; i++) {
if(i >= this->m_data_map.count()) {
this->m_data_map.append(QVector<QVariant>(max_colnum));
this->colorData.append(QVector<QColor>(max_colnum));
this->m_vec_hedlbls.append(QString::number(i));
} else {
if(this->m_data_map[i].count() < column + 1) { // 扩充
this->m_data_map[i].reserve(max_colnum);
// this->colorData[i].reserve(max_colnum);
for(size_t ci = this->colorData[i].count(); ci < max_colnum; ci++) {
this->colorData[i].append(QColor(255, 255, 255));
}
} else {
}
}
}
}
}
void QueryDataTableModel::clear()
{
beginResetModel();
// m_table_map.clear();
m_data_map.clear();
m_hor_hedlbls.clear();
m_vec_hedlbls.clear();
m_highlight_indexs.clear();
endResetModel();
}
QVariant* QueryDataTableModel::getVariantPtr(size_t row, size_t col)
{
return &(this->m_data_map[row][col]);
// return nullptr;
}
void QueryDataTableModel::setDeleteFlag(int row, bool flag)
{
this->isdeletes[row] = flag;
if(flag) {
for(int i = 0; i < this->m_hor_hedlbls.size(); i++) {
this->colorData[row][i] = QColor(255, 0, 0); // 删除标记
}
} else {
for(int i = 0; i < this->m_hor_hedlbls.size(); i++) {
this->colorData[row][i] = QColor(255, 255, 255); // 非删除标记
}
}
}
bool QueryDataTableModel::getDeleteFlag(int row)
{
return this->isdeletes[row];
}
} // RCSDBManagerTool

View File

@ -0,0 +1,100 @@
//
// Created by 30453 on 25-6-26.
//
#ifndef QUERYDATATABLEMODEL_H
#define QUERYDATATABLEMODEL_H
#include "PluginRCSDBManagerAPI.h"
#include <QAbstractTableModel>
#include <QObject>
#include <QStringList>
#include <QVector>
#include <QVariant>
#include <QStringList>
#include <RCSDBManagerClass.h>
namespace RCSDBManagerTool {
QString getSaveFilePath(QWidget* parent, const QString& caption, const QString& filter);
class PLUGINRCSDBMANAGERAPI QueryDataTableModel : public QAbstractTableModel {
Q_OBJECT;
private:
QStringList m_hor_hedlbls; // headerlabels
QStringList m_vec_hedlbls; // oids - map.keys()
QVector<QVector<QVariant>> m_data_map;
QVector<QPair<int, int>> m_highlight_indexs; // 背景高亮的indexs
QVector<QVector<QColor>> colorData;
QString csvPath;
QVector<bool> isdeletes;// 用于标记是否删除
public:
explicit QueryDataTableModel(QObject* parent = nullptr);
~QueryDataTableModel();
public:
void loadProjectDescDataSet(std::vector<ProjectDesc> projectdescSets);
void loadRCSRecordDataSet(std::vector<RCSRecord> RCSRecordSets);
void saveCSVFilePath(QString csvpath);
void saveFilePath();
public:
QStringList getColumnNames();
QStringList getItemDataByColumn(int colidx);
int getColumnIdxByColumName(QString ColumnName);
virtual QString getCSVPath();
// tableview 表格模型操作
void SetData(const QVector<QVector<QVariant>>& map, QStringList& colnames, QStringList& rowIds);
void setHignlightIndex(QVector<QPair<int, int>> vec_index);
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex& parent) const;
virtual int columnCount(const QModelIndex& parent) const;
virtual QVariant data(const QModelIndex& index, int role) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = 2);
QString itemText(int row, int column) const;
QString itemText(const QModelIndex& index) const;
void setItemText(const QModelIndex& index, const QString& str);
void setItemText(int row, int column, const QString& str);
QVariant ItemData(const QModelIndex& index) const;
QVariant ItemData(int row, int column) const;
void SetItemData(const QModelIndex& index, const QVariant& data);
void SetItemData(int row, int column, const QVariant& data);
size_t rowCount();
size_t colCount();
void isNeedExtendTable(size_t row, size_t col);
void clear();
QVariant* getVariantPtr(size_t row, size_t col);
virtual void setDeleteFlag(int row, bool flag);
virtual bool getDeleteFlag(int row);
signals:
void itemChanged(const QModelIndex& index, const QVariant& value);
}; // RCSDBManagerTool
};
#endif //QUERYDATATABLEMODEL_H

View File

@ -12,13 +12,12 @@
#include "PluginWBFZExchangePlugin/FEKOBaseToolClass.h" #include "PluginWBFZExchangePlugin/FEKOBaseToolClass.h"
namespace RCSDBManagerTool { namespace RCSDBManagerTool {
RCSDBManagerClass* RCSDBManagerClass::_ins = nullptr; RCSDBManagerClass *RCSDBManagerClass::_ins = nullptr;
RCSDBManagerClass::RCSDBManagerClass(const std::string& dbPath) : _db(nullptr), _dbPath(dbPath) { RCSDBManagerClass::RCSDBManagerClass(const std::string &dbPath) : _db(nullptr), _dbPath(dbPath) {
this->initializeDatabase(dbPath); this->initializeDatabase(dbPath);
qDebug() <<u8"Create database file " << QString::fromStdString(dbPath) ; qDebug() << u8"Create database file " << QString::fromStdString(dbPath);
this->initialize(); this->initialize();
} }
@ -28,42 +27,42 @@ namespace RCSDBManagerTool {
bool RCSDBManagerClass::initialize() { bool RCSDBManagerClass::initialize() {
if (!_db) { if (!_db) {
qDebug() <<u8"数据库未连接" ; qDebug() << u8"数据库未连接";
return false; return false;
} }
return true; return true;
} }
bool RCSDBManagerClass::createTables() { bool RCSDBManagerClass::createTables() {
const char* sql1 = "CREATE TABLE IF NOT EXISTS RCSProjectFolderTable (" const char *sql1 = "CREATE TABLE IF NOT EXISTS RCSProjectFolderTable ("
"ProjectID INTEGER PRIMARY KEY AUTOINCREMENT," "ProjectID INTEGER PRIMARY KEY AUTOINCREMENT,"
"projectname TEXT NOT NULL," "projectname TEXT NOT NULL,"
"projectFolder TEXT NOT NULL," "projectFolder TEXT NOT NULL,"
"desc TEXT)"; "desc TEXT)";
const char* sql2 = "CREATE TABLE IF NOT EXISTS RCSDataTable (" const char *sql2 = "CREATE TABLE IF NOT EXISTS RCSDataTable ("
"ProjectID INTEGER," "ProjectID INTEGER,"
"freq REAL," "freq REAL,"
"az REAL," "az REAL,"
"inc REAL," "inc REAL,"
"Transpolar REAL," "Transpolar REAL,"
"E_H_real REAL," "E_H_real REAL,"
"E_H_imag REAL," "E_H_imag REAL,"
"E_V_real REAL," "E_V_real REAL,"
"E_V_imag REAL," "E_V_imag REAL,"
"RCS_H REAL," "RCS_H REAL,"
"RCS_V REAL," "RCS_V REAL,"
"FOREIGN KEY(ProjectID) REFERENCES RCSProjectFolderTable(ProjectID))"; "FOREIGN KEY(ProjectID) REFERENCES RCSProjectFolderTable(ProjectID))";
char* errMsg = nullptr; char *errMsg = nullptr;
if (sqlite3_exec(_db, sql1, nullptr, nullptr, &errMsg) != SQLITE_OK) { if (sqlite3_exec(_db, sql1, nullptr, nullptr, &errMsg) != SQLITE_OK) {
qDebug() <<u8"创建RCSProjectFolderTable表失败: " << QString::fromStdString(errMsg) ; qDebug() << u8"创建RCSProjectFolderTable表失败: " << QString::fromStdString(errMsg);
sqlite3_free(errMsg); sqlite3_free(errMsg);
return false; return false;
} }
if (sqlite3_exec(_db, sql2, nullptr, nullptr, &errMsg) != SQLITE_OK) { if (sqlite3_exec(_db, sql2, nullptr, nullptr, &errMsg) != SQLITE_OK) {
qDebug() <<u8"创建RCSData表失败: " << QString::fromStdString(errMsg) ; qDebug() << u8"创建RCSData表失败: " << QString::fromStdString(errMsg);
sqlite3_free(errMsg); sqlite3_free(errMsg);
return false; return false;
} }
@ -72,15 +71,15 @@ namespace RCSDBManagerTool {
} }
bool RCSDBManagerClass::insertRCSDataRecord(int projectId, double freq, double az, double inc, bool RCSDBManagerClass::insertRCSDataRecord(int projectId, double freq, double az, double inc,
double transpolar, double eHReal, double eHImag, double transpolar, double eHReal, double eHImag,
double eVReal, double eVImag, double rcsH, double rcsV) { double eVReal, double eVImag, double rcsH, double rcsV) {
const char* sql = "INSERT INTO RCSDataTable (ProjectID, freq, az, inc, Transpolar, " const char *sql = "INSERT INTO RCSDataTable (ProjectID, freq, az, inc, Transpolar, "
"E_H_real, E_H_imag, E_V_real, E_V_imag, RCS_H, RCS_V) " "E_H_real, E_H_imag, E_V_real, E_V_imag, RCS_H, RCS_V) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return false; return false;
} }
@ -97,7 +96,7 @@ namespace RCSDBManagerTool {
sqlite3_bind_double(stmt, 11, rcsV); sqlite3_bind_double(stmt, 11, rcsV);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"插入记录失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"插入记录失败: " << sqlite3_errmsg(_db);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return false; return false;
} }
@ -107,12 +106,13 @@ namespace RCSDBManagerTool {
} }
bool RCSDBManagerClass::deleteRCSDataRecord(int projectId, double freq, double az, bool RCSDBManagerClass::deleteRCSDataRecord(int projectId, double freq, double az,
double inc, double transpolar) { double inc, double transpolar) {
const char* sql = "DELETE FROM RCSDataTable WHERE ProjectID = ? AND freq = ? AND az = ? AND inc = ? AND Transpolar = ?"; const char *sql =
"DELETE FROM RCSDataTable WHERE ProjectID = ? AND freq = ? AND az = ? AND inc = ? AND Transpolar = ?";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << QString::fromStdString(sqlite3_errmsg(_db) ) ; qDebug() << u8"准备SQL语句失败: " << QString::fromStdString(sqlite3_errmsg(_db));
return false; return false;
} }
@ -123,7 +123,7 @@ namespace RCSDBManagerTool {
sqlite3_bind_double(stmt, 5, transpolar); sqlite3_bind_double(stmt, 5, transpolar);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"删除记录失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"删除记录失败: " << sqlite3_errmsg(_db);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return false; return false;
} }
@ -133,16 +133,16 @@ namespace RCSDBManagerTool {
} }
bool RCSDBManagerClass::updateRCSDataRecord(int projectId, double freq, double az, double inc, bool RCSDBManagerClass::updateRCSDataRecord(int projectId, double freq, double az, double inc,
double transpolar, double newEHReal, double newEHImag, double transpolar, double newEHReal, double newEHImag,
double newEVReal, double newEVImag, double newRCSH, double newRCSV) { double newEVReal, double newEVImag, double newRCSH, double newRCSV) {
const char* sql = "UPDATE RCSDataTable SET " const char *sql = "UPDATE RCSDataTable SET "
"E_H_real = ?, E_H_imag = ?, E_V_real = ?, E_V_imag = ?, " "E_H_real = ?, E_H_imag = ?, E_V_real = ?, E_V_imag = ?, "
"RCS_H = ?, RCS_V = ? " "RCS_H = ?, RCS_V = ? "
"WHERE ProjectID = ? AND freq = ? AND az = ? AND inc = ? AND Transpolar = ?"; "WHERE ProjectID = ? AND freq = ? AND az = ? AND inc = ? AND Transpolar = ?";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return false; return false;
} }
@ -159,7 +159,7 @@ namespace RCSDBManagerTool {
sqlite3_bind_double(stmt, 11, transpolar); sqlite3_bind_double(stmt, 11, transpolar);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"更新记录失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"更新记录失败: " << sqlite3_errmsg(_db);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return false; return false;
} }
@ -169,7 +169,7 @@ namespace RCSDBManagerTool {
} }
std::vector<RCSRecord> RCSDBManagerClass::queryRCSDataRecords(int projectId, double freq, std::vector<RCSRecord> RCSDBManagerClass::queryRCSDataRecords(int projectId, double freq,
double az, double inc, double transpolar) { double az, double inc, double transpolar) {
std::vector<RCSRecord> results; std::vector<RCSRecord> results;
std::string sql = "SELECT * FROM RCSDataTable WHERE 1=1"; std::string sql = "SELECT * FROM RCSDataTable WHERE 1=1";
@ -179,9 +179,9 @@ namespace RCSDBManagerTool {
if (inc != -1.0) sql += " AND inc = ?"; if (inc != -1.0) sql += " AND inc = ?";
if (transpolar != -1.0) sql += " AND Transpolar = ?"; if (transpolar != -1.0) sql += " AND Transpolar = ?";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return results; return results;
} }
@ -197,8 +197,8 @@ namespace RCSDBManagerTool {
int colCount = sqlite3_column_count(stmt); int colCount = sqlite3_column_count(stmt);
for (int i = 0; i < colCount; i++) { for (int i = 0; i < colCount; i++) {
const char* colName = sqlite3_column_name(stmt, i); const char *colName = sqlite3_column_name(stmt, i);
const char* colValue = reinterpret_cast<const char*>(sqlite3_column_text(stmt, i)); const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
if (colName && colValue) { if (colName && colValue) {
if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue); if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue);
@ -241,6 +241,124 @@ namespace RCSDBManagerTool {
return results; return results;
} }
std::vector<ProjectDesc> RCSDBManagerClass::queryPRrojectDescByProjectName(std::string pronamestr) {
std::vector<ProjectDesc> result;
// SQL 查询语句基于项目ID查询 ProjectDesc 数据
const std::string sql = "SELECT projectID, projectName, projectDesc, projectFolder "
"FROM Projects WHERE projectname = ?";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return result;
}
sqlite3_bind_text(stmt, 1, pronamestr.c_str(),-1, SQLITE_TRANSIENT);
while (sqlite3_step(stmt) == SQLITE_ROW) {
ProjectDesc record;
int colCount = sqlite3_column_count(stmt);
for (int i = 0; i < colCount; i++) {
const char *colName = sqlite3_column_name(stmt, i);
const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
if (colName && colValue) {
if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue);
else if (strcmp(colName, "projectName") == 0) record.projectName = colValue;
else if (strcmp(colName, "projectFolder") == 0) record.projectFolder = colValue;
else if (strcmp(colName, "projectDesc") == 0) record.projectDesc = colValue;
}
}
result.push_back(record);
}
sqlite3_finalize(stmt);
return result;
}
std::vector<ProjectDesc> RCSDBManagerClass::queryPRrojectDescByProjectID(int projectID) {
std::vector<ProjectDesc> result;
// SQL 查询语句基于项目ID查询 ProjectDesc 数据
const std::string sql = "SELECT projectID, projectName, projectDesc, projectFolder "
"FROM Projects WHERE projectID = ?";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return result;
}
sqlite3_bind_int(stmt, 1, projectID);
while (sqlite3_step(stmt) == SQLITE_ROW) {
ProjectDesc record;
int colCount = sqlite3_column_count(stmt);
for (int i = 0; i < colCount; i++) {
const char *colName = sqlite3_column_name(stmt, i);
const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
if (colName && colValue) {
if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue);
else if (strcmp(colName, "projectName") == 0) record.projectName = colValue;
else if (strcmp(colName, "projectFolder") == 0) record.projectFolder = colValue;
else if (strcmp(colName, "projectDesc") == 0) record.projectDesc = colValue;
}
}
result.push_back(record);
}
sqlite3_finalize(stmt);
return result;
}
std::vector<ProjectDesc> RCSDBManagerClass::getAllProjectRecords() {
std::vector<ProjectDesc> result;
const std::string sql = "SELECT projectID, projectName, projectDesc, projectFolder FROM Projects";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return result;
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
ProjectDesc record;
int colCount = sqlite3_column_count(stmt);
for (int i = 0; i < colCount; i++) {
const char *colName = sqlite3_column_name(stmt, i);
const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
if (colName && colValue) {
if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue);
else if (strcmp(colName, "projectName") == 0) record.projectName = colValue;
else if (strcmp(colName, "projectFolder") == 0) record.projectFolder = colValue;
else if (strcmp(colName, "projectDesc") == 0) record.projectDesc = colValue;
}
}
result.push_back(record);
}
sqlite3_finalize(stmt);
return result;
}
bool RCSDBManagerClass::executeSQL(const std::string &sql) {
return false;
}
bool RCSDBManagerClass::executeSQLWithParams(const std::string &sql,
const std::vector<std::pair<int, std::string> > &params) {
return false;
}
void RCSDBManagerClass::closeDatabase() { void RCSDBManagerClass::closeDatabase() {
if (_db) { if (_db) {
sqlite3_close(_db); sqlite3_close(_db);
@ -248,50 +366,50 @@ namespace RCSDBManagerTool {
} }
} }
bool RCSDBManagerClass::initializeDatabase(const std::string& dbFilePath) { bool RCSDBManagerClass::initializeDatabase(const std::string &dbFilePath) {
// 检查数据库文件是否存在 // 检查数据库文件是否存在
FILE* file = fopen(dbFilePath.c_str(), "r"); FILE *file = fopen(dbFilePath.c_str(), "r");
bool dbExists = (file != nullptr); bool dbExists = (file != nullptr);
if (file) fclose(file); if (file) fclose(file);
if (!dbExists) { if (!dbExists) {
qDebug() <<u8"数据库文件不存在,正在创建:" << QString::fromStdString(dbFilePath) ; qDebug() << u8"数据库文件不存在,正在创建:" << QString::fromStdString(dbFilePath);
if (sqlite3_open(dbFilePath.c_str(), &_db) != SQLITE_OK) { if (sqlite3_open(dbFilePath.c_str(), &_db) != SQLITE_OK) {
qDebug() <<u8"无法打开或创建数据库:" << sqlite3_errmsg(_db) ; qDebug() << u8"无法打开或创建数据库:" << sqlite3_errmsg(_db);
return false; return false;
} }
if (!createTables()) { if (!createTables()) {
qDebug() <<u8"初始化数据库表失败" ; qDebug() << u8"初始化数据库表失败";
return false; return false;
} }
qDebug() <<u8"数据库文件已成功创建并初始化:" << QString::fromStdString(dbFilePath) ; qDebug() << u8"数据库文件已成功创建并初始化:" << QString::fromStdString(dbFilePath);
return true; return true;
} else { } else {
qDebug() <<u8"数据库文件已存在:" << QString::fromStdString(dbFilePath) ; qDebug() << u8"数据库文件已存在:" << QString::fromStdString(dbFilePath);
if (sqlite3_open(dbFilePath.c_str(), &_db) != SQLITE_OK) { if (sqlite3_open(dbFilePath.c_str(), &_db) != SQLITE_OK) {
qDebug() <<u8"无法打开现有数据库:" << sqlite3_errmsg(_db) ; qDebug() << u8"无法打开现有数据库:" << sqlite3_errmsg(_db);
return false; return false;
} }
if (!checkAndCreateTables()) { if (!checkAndCreateTables()) {
qDebug() <<u8"检查或创建表失败" ; qDebug() << u8"检查或创建表失败";
return false; return false;
} }
qDebug() <<u8"数据库表已成功检查和更新:" << QString::fromStdString(dbFilePath) ; qDebug() << u8"数据库表已成功检查和更新:" << QString::fromStdString(dbFilePath);
return true; return true;
} }
} }
bool RCSDBManagerClass::checkAndCreateTables() { bool RCSDBManagerClass::checkAndCreateTables() {
const char* sql1 = "SELECT name FROM sqlite_master WHERE type='table' AND name='RCSProjectFolderTable'"; const char *sql1 = "SELECT name FROM sqlite_master WHERE type='table' AND name='RCSProjectFolderTable'";
const char* sql2 = "SELECT name FROM sqlite_master WHERE type='table' AND name='RCSDataTable'"; const char *sql2 = "SELECT name FROM sqlite_master WHERE type='table' AND name='RCSDataTable'";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
bool table1Exists = false; bool table1Exists = false;
bool table2Exists = false; bool table2Exists = false;
@ -319,30 +437,30 @@ namespace RCSDBManagerTool {
return true; return true;
} }
RCSDBManagerClass* RCSDBManagerClass::instance() { RCSDBManagerClass *RCSDBManagerClass::instance() {
if (_ins == nullptr) { if (_ins == nullptr) {
// 这里需要替换为获取数据库路径的实际方法 // 这里需要替换为获取数据库路径的实际方法
const char* datastr=Setting::BusAPI::instance()->getRcsdbFilePath().toUtf8().constData(); const char *datastr = Setting::BusAPI::instance()->getRcsdbFilePath().toUtf8().constData();
qDebug()<<u8"数据库地址:"<<QString::fromStdString(datastr) ; qDebug() << u8"数据库地址:" << QString::fromStdString(datastr);
std::string sqldbpath(datastr); std::string sqldbpath(datastr);
_ins = new RCSDBManagerClass(sqldbpath); _ins = new RCSDBManagerClass(sqldbpath);
} }
return _ins; return _ins;
} }
int RCSDBManagerClass::insertProject(const std::string& projectName, const std::string& projectFolder, int RCSDBManagerClass::insertProject(const std::string &projectName, const std::string &projectFolder,
const std::string& desc) { const std::string &desc) {
if (!_db) { if (!_db) {
qDebug() <<u8"数据库未连接" ; qDebug() << u8"数据库未连接";
return -1; return -1;
} }
const char* sql = "INSERT INTO RCSProjectFolderTable (projectname, projectFolder, desc) " const char *sql = "INSERT INTO RCSProjectFolderTable (projectname, projectFolder, desc) "
"VALUES (?, ?, ?)"; "VALUES (?, ?, ?)";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return -1; return -1;
} }
@ -351,7 +469,7 @@ namespace RCSDBManagerTool {
sqlite3_bind_text(stmt, 3, desc.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, desc.c_str(), -1, SQLITE_TRANSIENT);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"插入失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"插入失败: " << sqlite3_errmsg(_db);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return -1; return -1;
} }
@ -361,8 +479,7 @@ namespace RCSDBManagerTool {
return id; return id;
} }
std::vector<RCSRecord> RCSDBManagerClass::queryProjects(int projectId, std::vector<RCSRecord> RCSDBManagerClass::queryProjects(int projectId, const std::string &projectName) {
const std::string& projectName) {
std::vector<RCSRecord> results; std::vector<RCSRecord> results;
if (!_db) return results; if (!_db) return results;
@ -370,9 +487,9 @@ namespace RCSDBManagerTool {
if (projectId != -1) sql += " AND ProjectID = ?"; if (projectId != -1) sql += " AND ProjectID = ?";
if (!projectName.empty()) sql += " AND projectname LIKE ?"; if (!projectName.empty()) sql += " AND projectname LIKE ?";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return results; return results;
} }
@ -388,8 +505,8 @@ namespace RCSDBManagerTool {
int colCount = sqlite3_column_count(stmt); int colCount = sqlite3_column_count(stmt);
for (int i = 0; i < colCount; i++) { for (int i = 0; i < colCount; i++) {
const char* colName = sqlite3_column_name(stmt, i); const char *colName = sqlite3_column_name(stmt, i);
const char* colValue = reinterpret_cast<const char*>(sqlite3_column_text(stmt, i)); const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
if (colName && colValue) { if (colName && colValue) {
if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue); if (strcmp(colName, "projectID") == 0) record.projectID = atoi(colValue);
@ -435,18 +552,18 @@ namespace RCSDBManagerTool {
bool RCSDBManagerClass::deleteProject(int projectId) { bool RCSDBManagerClass::deleteProject(int projectId) {
if (!_db) return false; if (!_db) return false;
const char* sql = "DELETE FROM RCSProjectFolderTable WHERE ProjectID = ?"; const char *sql = "DELETE FROM RCSProjectFolderTable WHERE ProjectID = ?";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return false; return false;
} }
sqlite3_bind_int(stmt, 1, projectId); sqlite3_bind_int(stmt, 1, projectId);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"删除失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"删除失败: " << sqlite3_errmsg(_db);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return false; return false;
} }
@ -456,36 +573,36 @@ namespace RCSDBManagerTool {
return changes > 0; return changes > 0;
} }
bool RCSDBManagerClass::insertRCSDataRecords(std::vector<RCSRecord>& records, bool RCSDBManagerClass::insertRCSDataRecords(std::vector<RCSRecord> &records,
int32_t projectID, double transpolarAngle) { int32_t projectID, double transpolarAngle) {
if (records.empty()) { if (records.empty()) {
qDebug() <<u8"没有数据需要插入" ; qDebug() << u8"没有数据需要插入";
return true; return true;
} }
if (!_db) return false; if (!_db) return false;
// 开始事务 // 开始事务
char* errMsg = nullptr; char *errMsg = nullptr;
if (sqlite3_exec(_db, "BEGIN TRANSACTION", nullptr, nullptr, &errMsg) != SQLITE_OK) { if (sqlite3_exec(_db, "BEGIN TRANSACTION", nullptr, nullptr, &errMsg) != SQLITE_OK) {
qDebug() <<u8"开始事务失败: " << errMsg ; qDebug() << u8"开始事务失败: " << errMsg;
sqlite3_free(errMsg); sqlite3_free(errMsg);
return false; return false;
} }
const char* sql = "INSERT INTO RCSDataTable " const char *sql = "INSERT INTO RCSDataTable "
"(ProjectID, freq, az, inc, Transpolar, E_H_real, E_H_imag, E_V_real, E_V_imag, RCS_H, RCS_V) " "(ProjectID, freq, az, inc, Transpolar, E_H_real, E_H_imag, E_V_real, E_V_imag, RCS_H, RCS_V) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
sqlite3_stmt* stmt; sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() <<u8"准备SQL语句失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
sqlite3_exec(_db, "ROLLBACK", nullptr, nullptr, nullptr); sqlite3_exec(_db, "ROLLBACK", nullptr, nullptr, nullptr);
return false; return false;
} }
bool success = true; bool success = true;
for (const auto& data : records) { for (const auto &data: records) {
sqlite3_bind_int(stmt, 1, projectID); sqlite3_bind_int(stmt, 1, projectID);
sqlite3_bind_double(stmt, 2, data.frequency); sqlite3_bind_double(stmt, 2, data.frequency);
sqlite3_bind_double(stmt, 3, data.phi); sqlite3_bind_double(stmt, 3, data.phi);
@ -499,7 +616,7 @@ namespace RCSDBManagerTool {
sqlite3_bind_double(stmt, 11, data.RCS_Theta); sqlite3_bind_double(stmt, 11, data.RCS_Theta);
if (sqlite3_step(stmt) != SQLITE_DONE) { if (sqlite3_step(stmt) != SQLITE_DONE) {
qDebug() <<u8"批量插入失败: " << sqlite3_errmsg(_db) ; qDebug() << u8"批量插入失败: " << sqlite3_errmsg(_db);
success = false; success = false;
break; break;
} }
@ -511,7 +628,7 @@ namespace RCSDBManagerTool {
if (success) { if (success) {
if (sqlite3_exec(_db, "COMMIT", nullptr, nullptr, &errMsg) != SQLITE_OK) { if (sqlite3_exec(_db, "COMMIT", nullptr, nullptr, &errMsg) != SQLITE_OK) {
qDebug() <<u8"提交事务失败: " << errMsg ; qDebug() << u8"提交事务失败: " << errMsg;
sqlite3_free(errMsg); sqlite3_free(errMsg);
return false; return false;
} }
@ -523,83 +640,117 @@ namespace RCSDBManagerTool {
} }
bool copyDirectory(const QString &sourcePath, const QString &targetPath, bool coverFileIfExist ) std::vector<std::string> RCSDBManagerClass::getAllProjectNames() {
{ // 获取RCSDBManagerClass的实例
QDir sourceDir(sourcePath); const char *sql = "SELECT * FROM RCSProjectFolderTable WHERE 1=1";
if(!sourceDir.exists()) {
qDebug() << u8"Source directory not exists:" << sourcePath;
return false;
}
QDir targetDir(targetPath); // 调用queryProjects方法传入默认值
if(!targetDir.exists()) { sqlite3_stmt *stmt;
if(!targetDir.mkpath(targetPath)) { if (sqlite3_prepare_v2(_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
qDebug() << u8"Failed to create target directory:" << targetPath; qDebug() << u8"准备SQL语句失败: " << sqlite3_errmsg(_db);
return false; QMessageBox::warning(0, u8"警告", u8"工程表查询失败");
} return std::vector<std::string>();
} }
std::vector<std::string> projectNames;
while (sqlite3_step(stmt) == SQLITE_ROW) {
ProjectDesc record;
int colCount = sqlite3_column_count(stmt);
QFileInfoList fileInfoList = sourceDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); for (int i = 0; i < colCount; i++) {
foreach(const QFileInfo &fileInfo, fileInfoList) { const char *colName = sqlite3_column_name(stmt, i);
if(fileInfo.isDir()) { const char *colValue = reinterpret_cast<const char *>(sqlite3_column_text(stmt, i));
// 递归处理子目录
if(!copyDirectory(fileInfo.filePath(),
targetDir.filePath(fileInfo.fileName()),
coverFileIfExist)) {
return false;
}
} else {
// 处理文件
if(coverFileIfExist && targetDir.exists(fileInfo.fileName())) {
targetDir.remove(fileInfo.fileName());
}
if(!QFile::copy(fileInfo.filePath(), if (colName && colValue) {
targetDir.filePath(fileInfo.fileName()))) { if (strcmp(colName, "projectname") == 0) {
qDebug() << u8"Failed to copy file:" << fileInfo.filePath(); projectNames.push_back(colValue);
return false; break;
} } else {
} }
} }
return true; }
} }
QString writeUTF8StringFile(QString path,QString unicodeString) { return projectNames;
QFile fileOut(path); }
if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text))
{
return u8"";
}
QTextStream streamFileOut(&fileOut);
streamFileOut.setCodec("UTF-8");
streamFileOut << unicodeString;
streamFileOut.flush();
fileOut.close();
return path;
}
QFileInfoList findFilePath(const QString& strFilePath, const QString& strNameFilters, QDirIterator::IteratorFlag flag){
QFileInfoList fileList;
if (strFilePath.isEmpty() || strNameFilters.isEmpty())
{
return fileList;
}
QDir dir; ///////////////////////////////////////////////////////////////////////
QStringList filters;
filters << strNameFilters;
dir.setPath(strFilePath); bool copyDirectory(const QString &sourcePath, const QString &targetPath, bool coverFileIfExist) {
dir.setNameFilters(filters); QDir sourceDir(sourcePath);
QDirIterator iter(dir, flag); if (!sourceDir.exists()) {
while (iter.hasNext()) qDebug() << u8"Source directory not exists:" << sourcePath;
{ return false;
iter.next(); }
QFileInfo info = iter.fileInfo();
if (info.isFile()) QDir targetDir(targetPath);
{ if (!targetDir.exists()) {
fileList.append(info); if (!targetDir.mkpath(targetPath)) {
} qDebug() << u8"Failed to create target directory:" << targetPath;
} return false;
return fileList; }
} }
QFileInfoList fileInfoList = sourceDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
foreach(const QFileInfo &fileInfo, fileInfoList) {
if (fileInfo.isDir()) {
// 递归处理子目录
if (!copyDirectory(fileInfo.filePath(),
targetDir.filePath(fileInfo.fileName()),
coverFileIfExist)) {
return false;
}
} else {
// 处理文件
if (coverFileIfExist && targetDir.exists(fileInfo.fileName())) {
targetDir.remove(fileInfo.fileName());
}
if (!QFile::copy(fileInfo.filePath(),
targetDir.filePath(fileInfo.fileName()))) {
qDebug() << u8"Failed to copy file:" << fileInfo.filePath();
return false;
}
}
}
return true;
}
QString writeUTF8StringFile(QString path, QString unicodeString) {
QFile fileOut(path);
if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text)) {
return u8"";
}
QTextStream streamFileOut(&fileOut);
streamFileOut.setCodec("UTF-8");
streamFileOut << unicodeString;
streamFileOut.flush();
fileOut.close();
return path;
}
QFileInfoList findFilePath(const QString &strFilePath, const QString &strNameFilters,
QDirIterator::IteratorFlag flag) {
QFileInfoList fileList;
if (strFilePath.isEmpty() || strNameFilters.isEmpty()) {
return fileList;
}
QDir dir;
QStringList filters;
filters << strNameFilters;
dir.setPath(strFilePath);
dir.setNameFilters(filters);
QDirIterator iter(dir, flag);
while (iter.hasNext()) {
iter.next();
QFileInfo info = iter.fileInfo();
if (info.isFile()) {
fileList.append(info);
}
}
return fileList;
}
} // namespace RCSDBManagerTool } // namespace RCSDBManagerTool

View File

@ -63,6 +63,16 @@ namespace RCSDBManagerTool {
}; };
struct ProjectDesc {
int32_t projectID;
QString projectName;
QString projectDesc;
QString projectFolder;
};
class PLUGINRCSDBMANAGERAPI RCSDBManagerClass { class PLUGINRCSDBMANAGERAPI RCSDBManagerClass {
public: public:
static RCSDBManagerClass* instance(); static RCSDBManagerClass* instance();
@ -80,20 +90,23 @@ namespace RCSDBManagerTool {
double transpolar, double newEHReal, double newEHImag, double transpolar, double newEHReal, double newEHImag,
double newEVReal, double newEVImag, double newRCSH, double newRCSV); double newEVReal, double newEVImag, double newRCSH, double newRCSV);
std::vector<RCSRecord> queryRCSDataRecords(int projectId, double freq, std::vector<RCSRecord> queryRCSDataRecords(int projectId, double freq,double az, double inc, double transpolar);
double az, double inc, double transpolar);
std::vector<ProjectDesc> queryPRrojectDescByProjectName(std::string pronamestr);
std::vector<ProjectDesc> queryPRrojectDescByProjectID(int projectID);
std::vector<ProjectDesc> getAllProjectRecords();
void closeDatabase(); void closeDatabase();
int insertProject(const std::string& projectName, const std::string& projectFolder, int insertProject(const std::string& projectName, const std::string& projectFolder,
const std::string& desc); const std::string& desc);
std::vector<RCSRecord> queryProjects(int projectId, std::vector<RCSRecord> queryProjects(int projectId,const std::string& projectName);
const std::string& projectName);
bool deleteProject(int projectId); bool deleteProject(int projectId);
bool insertRCSDataRecords(std::vector<RCSRecord>& records, bool insertRCSDataRecords(std::vector<RCSRecord>& records,
int32_t projectID, double transpolarAngle); int32_t projectID, double transpolarAngle);
std::vector<std::string> getAllProjectNames();
private: private:
RCSDBManagerClass(const std::string& dbPath); RCSDBManagerClass(const std::string& dbPath);
bool initializeDatabase(const std::string& dbFilePath); bool initializeDatabase(const std::string& dbFilePath);

View File

@ -0,0 +1,64 @@
//
// Created by 30453 on 25-6-26.
//
// You may need to build the project (run Qt uic code generator) to get "ui_RCSDBQueryDialog.h" resolved
#include "RCSDBQueryDialog.h"
#include "RCSDBManagerClass.h"
#include "ui_RCSDBQueryDialog.h"
#include <QStandardItemModel>
#include <QFile>
#include <QTextStream>
namespace RCSDBManagerTool {
RCSDBQueryDialog::RCSDBQueryDialog(QWidget *parent) : QDialog(parent), ui(new Ui::RCSDBQueryDialog),
tableModel(new QStandardItemModel(this)) {
ui->setupUi(this);
this->init();
}
RCSDBQueryDialog::~RCSDBQueryDialog() {
delete ui;
}
void RCSDBQueryDialog::init() {
QObject::connect(ui->pushButtonQuery, SIGNAL(clicked()), this, SLOT(OnQueryData()));
QObject::connect(ui->pushButtonExportCSV, SIGNAL(clicked()), this, SLOT(OnExportCSV()));
RCSDBManagerClass *db = RCSDBManagerClass::instance();
}
void RCSDBQueryDialog::OnExportCSV() {
}
void RCSDBQueryDialog::OnQueryData() {
}
} // RCSDBManagerTool

View File

@ -0,0 +1,67 @@
//
// Created by 30453 on 25-6-26.
//
#ifndef RCSDBQUERYDIALOG_H
#define RCSDBQUERYDIALOG_H
#include "PluginRCSDBManagerAPI.h"
#include "MultiSelectComboBox.h" // 多选框
#include <QtSql/QSqlQueryModel>
#include <QStandardItemModel>
#include <QDialog>
#include <QAbstractTableModel>
#include <QtSql/QSqlTableModel>
#include <QObject>
#include <QStringList>
#include <QVector>
#include "RCSDBManagerClass.h"
namespace RCSDBManagerTool {
QT_BEGIN_NAMESPACE
namespace Ui {
class RCSDBQueryDialog;
}
QT_END_NAMESPACE
class PLUGINRCSDBMANAGERAPI RCSDBQueryDialog : public QDialog {
Q_OBJECT
public:
explicit RCSDBQueryDialog(QWidget *parent = nullptr);
~RCSDBQueryDialog() override;
public slots:
void init();
void OnExportCSV();
void OnQueryData();
private:
Ui::RCSDBQueryDialog *ui;
QStandardItemModel* tableModel;
};
} // RCSDBManagerTool
#endif //RCSDBQUERYDIALOG_H

View File

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RCSDBManagerTool::RCSDBQueryDialog</class>
<widget class="QDialog" name="RCSDBManagerTool::RCSDBQueryDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>559</height>
</rect>
</property>
<property name="windowTitle">
<string>RCSDBQueryDialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>查询条件</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>查询字段:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxQueryField">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<item>
<property name="text">
<string>ProjectID</string>
</property>
</item>
<item>
<property name="text">
<string>projectname</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>条件值:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxQueryValue">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="pushButtonQuery">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>查询</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>工程查询结果</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QTableWidget" name="tableWidgetProjectRecord"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>RCS查询结果</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>RCS查询结果</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTableWidget" name="SqltableWidget"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonExportCSV">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>导出</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,14 +1,15 @@
#pragma once #pragma once
#ifndef TABLEVIEWMODEL_H #ifndef TABLEVIEWMODEL_H
#define TABLEVIEWMODEL_H #define TABLEVIEWMODEL_H
#include "WBFZExchangePluginAPI.h"
#include "AllHead.h" #include "AllHead.h"
#include "WBFZExchangePluginAPI.h"
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
#include <QVector> #include <QVector>
class AbstractTableModel : public QAbstractTableModel { class WBFZAPI AbstractTableModel : public QAbstractTableModel {
Q_OBJECT; Q_OBJECT;
public: public:
@ -25,7 +26,7 @@ public:
}; };
// FKEOResult.csv 表格对应类 2023.07.25 重写类 // FKEOResult.csv 表格对应类 2023.07.25 重写类
class FEKOResultCsvTableModel : public AbstractTableModel { class WBFZAPI FEKOResultCsvTableModel : public AbstractTableModel {
Q_OBJECT; Q_OBJECT;
private: private: