diff --git a/CoordinateSetter/CoordinateSetter.pro b/CoordinateSetter/CoordinateSetter.pro new file mode 100644 index 0000000..632757f --- /dev/null +++ b/CoordinateSetter/CoordinateSetter.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-11-20T19:55:37 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = CoordinateSetter +TEMPLATE = app + + +SOURCES += main.cpp\ + coordinatesetter.cpp + +HEADERS += coordinatesetter.h + +FORMS += coordinatesetter.ui diff --git a/CoordinateSetter/CoordinateSetter.pro.user b/CoordinateSetter/CoordinateSetter.pro.user new file mode 100644 index 0000000..4965d88 --- /dev/null +++ b/CoordinateSetter/CoordinateSetter.pro.user @@ -0,0 +1,255 @@ + + + + + + EnvironmentId + {a8c18b7e-8020-49b9-a0ef-0165c784344f} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3 MinGW 32bit + Desktop Qt 5.3 MinGW 32bit + qt.53.win32_mingw482_kit + 0 + 0 + 0 + + C:/Users/fzyz_sb/Desktop/build-CoordinateSetter-Desktop_Qt_5_3_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/fzyz_sb/Desktop/build-CoordinateSetter-Desktop_Qt_5_3_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + CoordinateSetter + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/fzyz_sb/Desktop/CoordinateSetter/CoordinateSetter.pro + + CoordinateSetter.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/CoordinateSetter/coordinatesetter.cpp b/CoordinateSetter/coordinatesetter.cpp new file mode 100644 index 0000000..4023cba --- /dev/null +++ b/CoordinateSetter/coordinatesetter.cpp @@ -0,0 +1,83 @@ +#include "coordinatesetter.h" +#include "ui_coordinatesetter.h" + +CoordinateSetter::CoordinateSetter(QList *coords, + QWidget *parent) : + QDialog(parent), + ui(new Ui::CoordinateSetter) +{ + ui->setupUi(this); + + coordinates = coords; + + //创建0行两列 + tableWidget = new QTableWidget(0, 2); + tableWidget->setHorizontalHeaderLabels( + QStringList() << tr("X") << tr("Y")); + + for (int row = 0; row < coordinates->count(); ++row) { + QPointF point = coordinates->at(row); + //新增一行并显示行的内容 + addRow(); + tableWidget->item(row, 0)->setText(QString::number(point.x())); + tableWidget->item(row, 1)->setText(QString::number(point.y())); + } + + buttonBox = new QDialogButtonBox(Qt::Horizontal); + QPushButton *addRowButton = buttonBox->addButton(tr("&Add Row"), + QDialogButtonBox::ActionRole); + buttonBox->addButton(QDialogButtonBox::Ok); + buttonBox->addButton(QDialogButtonBox::Cancel); + + connect(addRowButton, SIGNAL(clicked()), this, SLOT(addRow())); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(tableWidget); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); + + setWindowTitle(tr("Coordinate Setter")); +} + +CoordinateSetter::~CoordinateSetter() +{ + delete ui; +} + + +//done的作用是当用户按下OK或者cancel后,执行的动作 +void CoordinateSetter::done(int result) +{ + //当接收到Accepted信号后,将数据存入coordinates中 + if (result == QDialog::Accepted) { + coordinates->clear(); + for (int row = 0; row < tableWidget->rowCount(); ++row) { + double x = tableWidget->item(row, 0)->text().toDouble(); + double y = tableWidget->item(row, 1)->text().toDouble(); + coordinates->append(QPointF(x, y)); + } + } + QDialog::done(result); +} + +void CoordinateSetter::addRow() +{ + int row = tableWidget->rowCount(); + + //在row后面插入一行,此时tableWidget为新增的一行 + tableWidget->insertRow(row); + + //设置第一列 + QTableWidgetItem *item0 = new QTableWidgetItem; + item0->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + tableWidget->setItem(row, 0, item0); + + //设置第二列 + QTableWidgetItem *item1 = new QTableWidgetItem; + item1->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); + tableWidget->setItem(row, 1, item1); + + tableWidget->setCurrentItem(item0); +} diff --git a/CoordinateSetter/coordinatesetter.h b/CoordinateSetter/coordinatesetter.h new file mode 100644 index 0000000..380c73b --- /dev/null +++ b/CoordinateSetter/coordinatesetter.h @@ -0,0 +1,36 @@ +#ifndef COORDINATESETTER_H +#define COORDINATESETTER_H + +#include +#include +#include +#include +#include + +namespace Ui { +class CoordinateSetter; +} + +class CoordinateSetter : public QDialog +{ + Q_OBJECT + +public: + CoordinateSetter(QList *coords, QWidget *parent = 0); + ~CoordinateSetter(); + + void done(int result); + +private slots: + void addRow(); + +private: + QTableWidget *tableWidget; + QDialogButtonBox *buttonBox; + QList *coordinates; + +private: + Ui::CoordinateSetter *ui; +}; + +#endif // COORDINATESETTER_H diff --git a/CoordinateSetter/coordinatesetter.ui b/CoordinateSetter/coordinatesetter.ui new file mode 100644 index 0000000..8048997 --- /dev/null +++ b/CoordinateSetter/coordinatesetter.ui @@ -0,0 +1,20 @@ + + CoordinateSetter + + + + 0 + 0 + 400 + 300 + + + + CoordinateSetter + + + + + + + diff --git a/CoordinateSetter/main.cpp b/CoordinateSetter/main.cpp new file mode 100644 index 0000000..29acb20 --- /dev/null +++ b/CoordinateSetter/main.cpp @@ -0,0 +1,22 @@ +#include "coordinatesetter.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QList coordinates; + coordinates << QPointF(0.0, 0.9) + << QPointF(0.2, 11.0) + << QPointF(0.4, 15.4) + << QPointF(0.6, 12.9) + << QPointF(0.8, 8.5) + << QPointF(1.0, 7.1) + << QPointF(1.2, 4.0) + << QPointF(1.4, 13.6) + << QPointF(1.6, 22.2) + << QPointF(1.8, 22.2); + CoordinateSetter coordinateSetter(&coordinates); + coordinateSetter.show(); + + return a.exec(); +}