Compare commits
No commits in common. "main" and "v1.2" have entirely different histories.
131
mainwindow.cpp
131
mainwindow.cpp
|
@ -12,7 +12,6 @@
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QSqlRecord>
|
#include <QSqlRecord>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QContextMenuEvent>
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -48,22 +47,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
QIcon convertIcon = QApplication::style()->standardIcon(QStyle::SP_ArrowRight);
|
QIcon convertIcon = QApplication::style()->standardIcon(QStyle::SP_ArrowRight);
|
||||||
textToSqliteAction->setIcon(convertIcon);
|
textToSqliteAction->setIcon(convertIcon);
|
||||||
sqliteToTextAction->setIcon(convertIcon);
|
sqliteToTextAction->setIcon(convertIcon);
|
||||||
|
|
||||||
firstColMenu = new QMenu(this);
|
|
||||||
QAction* addRowAboveAction = firstColMenu->addAction(tr("↑ 向上添加一行"));
|
|
||||||
QAction* addRowBelowAction = firstColMenu->addAction(tr("向下添加一行 ↓"));
|
|
||||||
QAction* delRowAction = firstColMenu->addAction(tr("删除"));
|
|
||||||
connect(addRowAboveAction, &QAction::triggered, this, &MainWindow::onAddRowAboveActionTriggered);
|
|
||||||
connect(addRowBelowAction, &QAction::triggered, this, &MainWindow::onAddRowBelowActionTriggered);
|
|
||||||
connect(delRowAction, &QAction::triggered, this, &MainWindow::onDelRowActionTriggered);
|
|
||||||
|
|
||||||
firstRowMenu = new QMenu(this);
|
|
||||||
QAction* addColAboveAction = firstRowMenu->addAction(tr("← 向左添加一列"));
|
|
||||||
QAction* addColBelowAction = firstRowMenu->addAction(tr("向右添加一列 →"));
|
|
||||||
QAction* delColAction = firstRowMenu->addAction(tr("删除"));
|
|
||||||
connect(addColAboveAction, &QAction::triggered, this, &MainWindow::onAddColAboveActionTriggered);
|
|
||||||
connect(addColBelowAction, &QAction::triggered, this, &MainWindow::onAddColBelowActionTriggered);
|
|
||||||
connect(delColAction, &QAction::triggered, this, &MainWindow::onDelColActionTriggered);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,108 +55,6 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::contextMenuEvent(QContextMenuEvent* event)
|
|
||||||
{
|
|
||||||
QPoint cellPos = ui->tableWidget->viewport()->mapFromGlobal(event->globalPos());
|
|
||||||
int currentColumn = ui->tableWidget->horizontalHeader()->logicalIndexAt(cellPos.x());
|
|
||||||
int currentRow = ui->tableWidget->rowAt(cellPos.y());
|
|
||||||
|
|
||||||
if (currentColumn == -1 && currentRow == -1) {
|
|
||||||
// 没有选中行也没有选中列,不显示菜单
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentColumn == -1 && currentRow >= 0) {
|
|
||||||
// 选中了行,显示行菜单
|
|
||||||
ui->tableWidget->selectRow(currentRow);
|
|
||||||
firstColMenu->popup(event->globalPos());
|
|
||||||
} else if (currentColumn >= 0 && currentRow == -1) {
|
|
||||||
// 选中了列,显示列菜单
|
|
||||||
ui->tableWidget->selectColumn(currentColumn);
|
|
||||||
firstRowMenu->popup(event->globalPos());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddRowAboveActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentRow = tableWidget->currentRow();
|
|
||||||
if (currentRow >= 0)
|
|
||||||
{
|
|
||||||
tableWidget->insertRow(currentRow);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 如果没有选中行,在末尾追加一行
|
|
||||||
int newRow = tableWidget->rowCount();
|
|
||||||
tableWidget->insertRow(newRow);
|
|
||||||
currentRow = newRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddRowBelowActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentRow = tableWidget->currentRow();
|
|
||||||
if (currentRow >= 0)
|
|
||||||
{
|
|
||||||
tableWidget->insertRow(currentRow + 1); // 在下方插入一行
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 如果没有选中行,在末尾追加一行
|
|
||||||
int newRow = tableWidget->rowCount();
|
|
||||||
tableWidget->insertRow(newRow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddColAboveActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentColumn = tableWidget->currentColumn();
|
|
||||||
if (currentColumn >= 0)
|
|
||||||
{
|
|
||||||
tableWidget->insertColumn(currentColumn);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 如果没有选中列,在末尾追加一列
|
|
||||||
int newColumn = tableWidget->columnCount();
|
|
||||||
tableWidget->insertColumn(newColumn);
|
|
||||||
currentColumn = newColumn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onAddColBelowActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentColumn = tableWidget->currentColumn();
|
|
||||||
if (currentColumn >= 0)
|
|
||||||
{
|
|
||||||
tableWidget->insertColumn(currentColumn + 1); // 在右侧插入一列
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 如果没有选中列,在末尾追加一列
|
|
||||||
int newColumn = tableWidget->columnCount();
|
|
||||||
tableWidget->insertColumn(newColumn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onDelRowActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentRow = tableWidget->currentRow();
|
|
||||||
tableWidget->removeRow(currentRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onDelColActionTriggered()
|
|
||||||
{
|
|
||||||
QTableWidget* tableWidget = ui->tableWidget;
|
|
||||||
int currentColumn = tableWidget->currentColumn();
|
|
||||||
tableWidget->removeColumn(currentColumn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::showProgressDialog(const QString& labelText, int minimum, int maximum)
|
void MainWindow::showProgressDialog(const QString& labelText, int minimum, int maximum)
|
||||||
{
|
{
|
||||||
progressDialog = new QProgressDialog(labelText, "Cancel", minimum, maximum, this);
|
progressDialog = new QProgressDialog(labelText, "Cancel", minimum, maximum, this);
|
||||||
|
@ -245,12 +126,6 @@ void MainWindow::loadTextFile(const QString& fileName)
|
||||||
tableWidget->setHorizontalHeaderLabels(row);
|
tableWidget->setHorizontalHeaderLabels(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 补充空白内容,确保行的列数与表格的列数一致
|
|
||||||
while (row.count() < tableCol)
|
|
||||||
{
|
|
||||||
row.append(""); // 添加空白内容
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < tableCol; ++j)
|
for (int j = 0; j < tableCol; ++j)
|
||||||
{
|
{
|
||||||
QTableWidgetItem* item = new QTableWidgetItem(row.at(j));
|
QTableWidgetItem* item = new QTableWidgetItem(row.at(j));
|
||||||
|
@ -316,7 +191,7 @@ void MainWindow::onSaveButtonClicked()
|
||||||
out << "\t"; // 制表符分隔
|
out << "\t"; // 制表符分隔
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "\t"; // 最后一列再加一个制表符,以防万一
|
|
||||||
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +237,7 @@ void MainWindow::onSaveAsButtonClicked()
|
||||||
out << "\t"; // 制表符分隔
|
out << "\t"; // 制表符分隔
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "\t"; // 最后一列再加一个制表符,以防万一
|
|
||||||
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,7 +490,6 @@ void MainWindow::convertSqliteToText()
|
||||||
if (i < record.count() - 1)
|
if (i < record.count() - 1)
|
||||||
textStream << "\t";
|
textStream << "\t";
|
||||||
}
|
}
|
||||||
textStream << "\t";
|
|
||||||
textStream << "\r\n";
|
textStream << "\r\n";
|
||||||
|
|
||||||
++progress;
|
++progress;
|
||||||
|
@ -633,3 +507,4 @@ void MainWindow::convertSqliteToText()
|
||||||
|
|
||||||
QMessageBox::information(this, tr("Conversion Complete"), tr("SQLite to Text conversion completed successfully."));
|
QMessageBox::information(this, tr("Conversion Complete"), tr("SQLite to Text conversion completed successfully."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,25 +25,16 @@ public:
|
||||||
void convertTextToSqlite();
|
void convertTextToSqlite();
|
||||||
void convertSqliteToText();
|
void convertSqliteToText();
|
||||||
void showProgressDialog(const QString& labelText, int minimum, int maximum);
|
void showProgressDialog(const QString& labelText, int minimum, int maximum);
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onOpenButtonClicked();
|
void onOpenButtonClicked();
|
||||||
void onSaveButtonClicked();
|
void onSaveButtonClicked();
|
||||||
void onSaveAsButtonClicked();
|
void onSaveAsButtonClicked();
|
||||||
void onAddRowAboveActionTriggered();
|
|
||||||
void onAddRowBelowActionTriggered();
|
|
||||||
void onAddColAboveActionTriggered();
|
|
||||||
void onAddColBelowActionTriggered();
|
|
||||||
void onDelRowActionTriggered();
|
|
||||||
void onDelColActionTriggered();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QProgressDialog* progressDialog;
|
QProgressDialog* progressDialog;
|
||||||
QString openFilePath;
|
QString openFilePath;
|
||||||
QMenu* firstColMenu; // 右键菜单
|
|
||||||
QMenu* firstRowMenu; // 右键菜单
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -20,9 +20,6 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTableWidget" name="tableWidget"/>
|
<widget class="QTableWidget" name="tableWidget"/>
|
||||||
</item>
|
</item>
|
||||||
|
@ -49,6 +46,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuOpen"/>
|
<addaction name="menuOpen"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>打开</string>
|
<string>打开</string>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user