Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a86dfcfe97 | |||
5227ceaf5c | |||
4bd4ee655d | |||
dd9f9408c1 | |||
5744d80e69 |
125
mainwindow.cpp
125
mainwindow.cpp
|
@ -12,6 +12,7 @@
|
||||||
#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)
|
||||||
|
@ -47,6 +48,22 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +72,108 @@ 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);
|
||||||
|
@ -197,7 +316,7 @@ void MainWindow::onSaveButtonClicked()
|
||||||
out << "\t"; // 制表符分隔
|
out << "\t"; // 制表符分隔
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
out << "\t"; // 最后一列再加一个制表符,以防万一
|
||||||
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +362,7 @@ void MainWindow::onSaveAsButtonClicked()
|
||||||
out << "\t"; // 制表符分隔
|
out << "\t"; // 制表符分隔
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
out << "\t"; // 最后一列再加一个制表符,以防万一
|
||||||
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
out << "\r\n"; // 换行,注意使用\r\n表示换行符
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +615,7 @@ 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;
|
||||||
|
@ -513,4 +633,3 @@ 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,16 +25,25 @@ 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,6 +20,9 @@
|
||||||
<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>
|
||||||
|
@ -46,7 +49,6 @@
|
||||||
</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