Compare commits

..

No commits in common. "main" and "v1.3" have entirely different histories.
main ... v1.3

3 changed files with 4 additions and 134 deletions

View File

@ -12,7 +12,6 @@
#include <QInputDialog>
#include <QSqlRecord>
#include <QtDebug>
#include <QContextMenuEvent>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@ -48,22 +47,6 @@ MainWindow::MainWindow(QWidget *parent)
QIcon convertIcon = QApplication::style()->standardIcon(QStyle::SP_ArrowRight);
textToSqliteAction->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;
}
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)
{
progressDialog = new QProgressDialog(labelText, "Cancel", minimum, maximum, this);
@ -316,7 +197,7 @@ void MainWindow::onSaveButtonClicked()
out << "\t"; // 制表符分隔
}
}
out << "\t"; // 最后一列再加一个制表符,以防万一
out << "\r\n"; // 换行,注意使用\r\n表示换行符
}
@ -362,7 +243,7 @@ void MainWindow::onSaveAsButtonClicked()
out << "\t"; // 制表符分隔
}
}
out << "\t"; // 最后一列再加一个制表符,以防万一
out << "\r\n"; // 换行,注意使用\r\n表示换行符
}
@ -615,7 +496,6 @@ void MainWindow::convertSqliteToText()
if (i < record.count() - 1)
textStream << "\t";
}
textStream << "\t";
textStream << "\r\n";
++progress;
@ -633,3 +513,4 @@ void MainWindow::convertSqliteToText()
QMessageBox::information(this, tr("Conversion Complete"), tr("SQLite to Text conversion completed successfully."));
}

View File

@ -25,25 +25,16 @@ public:
void convertTextToSqlite();
void convertSqliteToText();
void showProgressDialog(const QString& labelText, int minimum, int maximum);
void contextMenuEvent(QContextMenuEvent* event);
private slots:
void onOpenButtonClicked();
void onSaveButtonClicked();
void onSaveAsButtonClicked();
void onAddRowAboveActionTriggered();
void onAddRowBelowActionTriggered();
void onAddColAboveActionTriggered();
void onAddColBelowActionTriggered();
void onDelRowActionTriggered();
void onDelColActionTriggered();
private:
Ui::MainWindow *ui;
QProgressDialog* progressDialog;
QString openFilePath;
QMenu* firstColMenu; // 右键菜单
QMenu* firstRowMenu; // 右键菜单
};
#endif // MAINWINDOW_H

View File

@ -20,9 +20,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTableWidget" name="tableWidget"/>
</item>
@ -49,6 +46,7 @@
</widget>
<addaction name="menuOpen"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen">
<property name="text">
<string>打开</string>