├── .gitignore ├── LICENSE ├── README.md ├── admin.cpp ├── admin.h ├── admin.ui ├── config.cpp ├── config.h ├── database.cpp ├── database.h ├── dialog.cpp ├── dialog.h ├── dialog.ui ├── drawmap.cpp ├── drawmap.h ├── in.cpp ├── in.h ├── in.ui ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── map.cpp ├── map.h ├── nav.cpp ├── nav.h ├── nav.ui ├── out.cpp ├── out.h ├── out.ui ├── parking.pro ├── parking.pro.user ├── parking.sql ├── tileset.cpp └── tileset.h /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.moc 20 | moc_*.cpp 21 | qrc_*.cpp 22 | ui_*.h 23 | Makefile* 24 | *-build-* 25 | 26 | # QtCreator 27 | 28 | *.autosave 29 | 30 | #QtCtreator Qml 31 | *.qmlproject.user 32 | *.qmlproject.user.* 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Gengrui Guo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | parking 2 | ===== 3 | 4 | Qt实现停车场管理软件 5 | 6 | 入库、出库、导航 7 | 8 | - Qt mysql操作 9 | - Qt 解析tiled生成的xml文件,并绘制图片 10 | - Qt 绘图 11 | 12 | Qsql, QSqlDatabase, QtXml, QVector ,QImage, QPrinter .... 13 | 14 | 环境 15 | 16 | ubuntu + mysql 17 | 18 | Todo 19 | 20 | - install qt 5.3 21 | - install mysql 5 22 | - import sql file 23 | - run -------------------------------------------------------------------------------- /admin.cpp: -------------------------------------------------------------------------------- 1 | #include "admin.h" 2 | #include "ui_admin.h" 3 | 4 | admin::admin(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::admin) { 7 | ui->setupUi(this); 8 | this -> adminConfig = new config(); 9 | this -> initWindow(); 10 | setWindowTitle("停车场管理系统"); 11 | } 12 | 13 | admin::~admin() { 14 | delete ui; 15 | } 16 | 17 | void admin::initWindow(){ 18 | 19 | } 20 | 21 | void admin::on_open_fille_clicked() { 22 | QString fileName = QFileDialog::getOpenFileName(this, 23 | tr("Open XML File"), "/home", tr("XML Files (*.xml)")); 24 | ui->FilePath->setText(fileName); 25 | } 26 | 27 | void admin::on_import_2_clicked() { 28 | QString xmlFilePath = ui -> FilePath ->text(); 29 | 30 | drawMap *map = new drawMap(xmlFilePath); 31 | map -> importXmlFile(); 32 | QImage mapImage = map -> convertXmlToImage(); 33 | nav *navShow = new nav(); 34 | navShow -> showImage(mapImage); 35 | 36 | this -> adminConfig ->setConfigOption("xmlpath", xmlFilePath); 37 | } 38 | 39 | void admin::on_viewmap_clicked() { 40 | QString xmlpath = this -> adminConfig ->getConfigOption("xmlpath"); 41 | drawMap *map = new drawMap(xmlpath); 42 | QImage mapImage = map -> convertXmlToImage(); 43 | nav *navShow = new nav(); 44 | navShow -> showImage(mapImage); 45 | } 46 | 47 | void admin::on_go_clicked() { 48 | 49 | QString xmlpath = this -> adminConfig ->getConfigOption("xmlpath"); 50 | QString to_pos_num = ui -> to_pos_num ->text(); 51 | 52 | drawMap *map = new drawMap(xmlpath); 53 | QImage mapImage = map -> draw_widh_nav(to_pos_num); 54 | nav *navShow = new nav(); 55 | navShow -> showImage(mapImage); 56 | } 57 | 58 | void admin::on_back_clicked() { 59 | MainWindow *m; 60 | m = new MainWindow(); 61 | this -> close(); 62 | m -> show(); 63 | } 64 | -------------------------------------------------------------------------------- /admin.h: -------------------------------------------------------------------------------- 1 | #ifndef ADMIN_H 2 | #define ADMIN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "config.h" 11 | #include "drawmap.h" 12 | #include "mainwindow.h" 13 | 14 | namespace Ui { 15 | class admin; 16 | } 17 | 18 | class admin : public QMainWindow 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit admin(QWidget *parent = 0); 24 | ~admin(); 25 | 26 | void initWindow(); 27 | 28 | private slots: 29 | void on_open_fille_clicked(); 30 | 31 | void on_import_2_clicked(); 32 | 33 | void on_viewmap_clicked(); 34 | 35 | void on_go_clicked(); 36 | 37 | void on_back_clicked(); 38 | 39 | private: 40 | Ui::admin *ui; 41 | config *adminConfig; 42 | }; 43 | 44 | #endif // ADMIN_H 45 | -------------------------------------------------------------------------------- /admin.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | admin 4 | 5 | 6 | 7 | 0 8 | 0 9 | 677 10 | 217 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | go 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | View map 36 | 37 | 38 | 39 | 40 | 41 | 42 | Import 43 | 44 | 45 | 46 | 47 | 48 | 49 | Back 50 | 51 | 52 | 53 | 54 | 55 | 56 | Import Map: 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Browse 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | config::config(){ 4 | //this -> xmlFilePath = this -> getConfigOption("xmlpath"); 5 | //this -> isLoaded = this -> getConfigOption("maploaded"); 6 | } 7 | 8 | QString config::getConfigOption(QString key){ 9 | // new database(); 10 | 11 | QSqlQuery configQuery; 12 | QString configSql = "SELECT `value` FROM `config` WHERE `key`='"+ key +"' LIMIT 1"; 13 | configQuery.prepare(configSql); 14 | 15 | if( !configQuery.exec() ){ 16 | qDebug() << configQuery.lastError(); 17 | QMessageBox msgBox; 18 | msgBox.setText("加载配置"+key+"时出错!"); 19 | msgBox.exec(); 20 | return NULL; 21 | } 22 | 23 | if(configQuery.next()){ 24 | return configQuery.value(0).toString(); 25 | } else { 26 | return NULL; 27 | } 28 | } 29 | 30 | void config::setConfigOption(QString key, QString value){ 31 | QSqlQuery configQuery; 32 | QString configSql = "INSERT INTO `config` (`key`, `value`) VALUES ('" + key + "','" + value + "')"; 33 | configQuery.prepare(configSql); 34 | 35 | if( !configQuery.exec() ){ 36 | QMessageBox msgBox; 37 | msgBox.setText("Database Error!"); 38 | msgBox.exec(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class config 9 | { 10 | public: 11 | config(); 12 | void setConfigOption(QString key, QString value); 13 | QString getConfigOption(QString key); 14 | //bool getConfigOption(QString key); 15 | 16 | 17 | // QString xmlFilePath; 18 | // QString isLoaded; 19 | }; 20 | 21 | #endif // CONFIG_H 22 | -------------------------------------------------------------------------------- /database.cpp: -------------------------------------------------------------------------------- 1 | #include "database.h" 2 | 3 | database::database(){ 4 | this -> db = QSqlDatabase::addDatabase("QMYSQL"); 5 | this -> db.setHostName("localhost"); 6 | this -> db.setDatabaseName("parking"); 7 | this -> db.setUserName("root"); 8 | this -> db.setPassword("123456"); 9 | bool conn = this -> db.open(); 10 | if (!conn) { 11 | QMessageBox msgBox; 12 | msgBox.setText("无法连接数据库,请检查数据库是否启动,数据库服务器地址是否正确!"); 13 | msgBox.exec(); 14 | } 15 | } 16 | 17 | database::~database(){ 18 | this -> db.close(); 19 | } 20 | -------------------------------------------------------------------------------- /database.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_H 2 | #define DATABASE_H 3 | 4 | #include 5 | #include 6 | 7 | class database 8 | { 9 | public: 10 | database(); 11 | ~database(); 12 | private: 13 | QSqlDatabase db; 14 | }; 15 | 16 | #endif // DATABASE_H 17 | -------------------------------------------------------------------------------- /dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include "ui_dialog.h" 3 | 4 | Dialog::Dialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::Dialog) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | Dialog::~Dialog() 12 | { 13 | delete ui; 14 | } 15 | bool Dialog::checkUser(){ 16 | QString username = ui->username->text(); 17 | QString password = ui->password->text(); 18 | qDebug() << username; 19 | QSqlQuery qry; 20 | qry.prepare( "SELECT * FROM `user` WHERE `username` = '"+username+"' and `password` = '"+password+"' LIMIT 1" ); 21 | if( !qry.exec() ){ 22 | qDebug() << qry.lastError(); 23 | return false; 24 | } else { 25 | if( qry.next() ){ 26 | qDebug()< checkUser()) { 37 | admin *adminWindow; 38 | adminWindow = new admin(); 39 | this -> close(); 40 | adminWindow -> show(); 41 | } else { 42 | QMessageBox msgBox; 43 | msgBox.setText("用户名密码错误!"); 44 | msgBox.exec(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include"admin.h" 7 | 8 | namespace Ui { 9 | class Dialog; 10 | } 11 | 12 | class Dialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit Dialog(QWidget *parent = 0); 18 | ~Dialog(); 19 | bool checkUser(); 20 | 21 | private slots: 22 | void on_login_clicked(); 23 | 24 | private: 25 | Ui::Dialog *ui; 26 | }; 27 | 28 | #endif // DIALOG_H 29 | -------------------------------------------------------------------------------- /dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 30 20 | 50 21 | 341 22 | 151 23 | 24 | 25 | 26 | 27 | 28 | 29 | Login 30 | 31 | 32 | 33 | 34 | 35 | 36 | QLineEdit::Password 37 | 38 | 39 | 40 | 41 | 42 | 43 | 用户名: 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 密码: 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /drawmap.cpp: -------------------------------------------------------------------------------- 1 | #include "drawmap.h" 2 | 3 | drawMap::drawMap(QString xmlFilePath){ 4 | this -> xmlFilePath = xmlFilePath; 5 | } 6 | 7 | // not use 8 | void drawMap::draw(){ 9 | this -> importXmlFile(); 10 | QImage mapImage = this -> convertXmlToImage(); 11 | 12 | nav * mapShow = new nav(); 13 | mapShow -> showImage(mapImage); 14 | } 15 | 16 | void drawMap::importXmlFile(){ 17 | QDomDocument xmlBOM; 18 | QFile f(this -> xmlFilePath); 19 | if (!f.open(QIODevice::ReadOnly )) { 20 | qDebug() << "Error while loading file"; 21 | return; 22 | } 23 | 24 | xmlBOM.setContent(&f); 25 | f.close(); 26 | 27 | 28 | QDomElement root = xmlBOM.documentElement(); 29 | QDomNodeList objectList = root.elementsByTagName("objectgroup").at(0).toElement().childNodes(); 30 | for (int o = 0; o < objectList.count(); o++) { 31 | QDomNode objectNode = objectList.at(o); 32 | QString x = objectNode.toElement().attribute("x"); 33 | QString y = objectNode.toElement().attribute("y"); 34 | QString width = objectNode.toElement().attribute("width"); 35 | QString height = objectNode.toElement().attribute("height"); 36 | QString type = objectNode.toElement().attribute("name"); 37 | 38 | QSqlQuery qry_config; 39 | QString sql_config = "INSERT INTO `config` (`key`, `value`) VALUES ('maploaded','true')"; 40 | qry_config.prepare(sql_config); 41 | 42 | if( !qry_config.exec() ){ 43 | qDebug() << qry_config.lastError(); 44 | return; 45 | } 46 | 47 | // save in mysql 48 | QSqlQuery qry; 49 | QString sql = "INSERT INTO `car_pos` (`x`, `y`, `width`, `height`, `status`, `type`, `pos_num`) VALUES ('" + x + "','" + y + "','" + width + "','" + height + "','free','" + type + "','" + QString::number(o+1) + "')"; 50 | qry.prepare(sql); 51 | if( !qry.exec() ){ 52 | qDebug() << qry.lastError(); 53 | return; 54 | } 55 | } 56 | } 57 | 58 | QImage drawMap::markParkingPos(QImage mapImage){ 59 | QSqlQuery qry; 60 | QString sql = "SELECT * FROM `car_pos` WHERE `type` = 'position'"; 61 | int x, y,width,heigth; 62 | QString pos, status; 63 | qry.prepare(sql); 64 | if( !qry.exec() ){ 65 | qDebug() << qry.lastError(); 66 | exit(0); 67 | } 68 | while( qry.next() ){ 69 | x = qry.value(1).toInt(); 70 | y = qry.value(2).toInt(); 71 | width = qry.value(3).toInt(); 72 | heigth = qry.value(4).toInt(); 73 | status = qry.value(5).toString(); 74 | pos = qry.value(7).toString(); 75 | QPainter mapPrinter(&mapImage); 76 | if(status == "full"){ 77 | mapPrinter.setPen(QPen(Qt::red, 6)); 78 | pos += "/有车"; 79 | } else { 80 | mapPrinter.setPen(QPen(Qt::yellow, 6)); 81 | pos += "/空闲"; 82 | } 83 | 84 | QPointF point = QPointF(x+10,y+heigth/2); 85 | mapPrinter.drawText(point,pos); 86 | } 87 | return mapImage; 88 | } 89 | 90 | QImage drawMap::convertXmlToImage(){ 91 | // open the xml fileMainWindow 92 | QDomDocument xmlBOM; 93 | QFile f(this -> xmlFilePath); 94 | if (!f.open(QIODevice::ReadOnly )) { 95 | qDebug() << "Error while loading file"; 96 | exit(0); 97 | } 98 | 99 | xmlBOM.setContent(&f); 100 | f.close(); 101 | 102 | //Get the root element 103 | QDomElement root = xmlBOM.documentElement(); 104 | 105 | //Get map info 106 | int mapWidth = root.attribute("width").toInt(); 107 | int mapHeight = root.attribute("height").toInt(); 108 | int tileWidth = root.attribute("tilewidth").toInt(); 109 | int tileHeight = root.attribute("tileheight").toInt(); 110 | 111 | map * map_created = new map(mapWidth, mapHeight, tileWidth, tileHeight); 112 | 113 | // Get tileset info! 114 | QDomNodeList tilesetList = root.elementsByTagName("tileset"); 115 | 116 | for(int i = 0; i < tilesetList.count(); i++) { 117 | QDomNode node = tilesetList.at(i); 118 | if(node.isElement()){ 119 | int imageWidth = node.toElement().firstChildElement().attribute("width").toInt(); 120 | int imageHeight = node.toElement().firstChildElement().attribute("height").toInt(); 121 | int firstGid = node.toElement().attribute("firstgid").toInt(); 122 | int tilewidth = node.toElement().attribute("tilewidth").toInt(); 123 | int tileheight = node.toElement().attribute("tileheight").toInt(); 124 | QString source = node.toElement().firstChildElement().attribute("source"); 125 | QString name = node.toElement().firstChildElement().attribute("name"); 126 | map_created -> tilesetVector.append(new tileset(imageWidth, imageHeight, firstGid, tilewidth, tileheight, source, name)); 127 | } 128 | } 129 | 130 | QSize mapSize( mapWidth * tileWidth, mapHeight * tileHeight ); 131 | QImage mapImage(mapSize,QImage::Format_RGB888); 132 | QPainter mapPainter(&mapImage); 133 | 134 | QDomNodeList layerList = root.elementsByTagName("layer"); 135 | 136 | for(int i = 0; i < layerList.count(); i++) { 137 | QDomNodeList tileList = layerList.at(i).childNodes().at(0).toElement().childNodes(); 138 | int tileLength = 0; 139 | int tileCount = tileList.count(); 140 | QVector tiles(tileCount); 141 | 142 | for(int j = 0; j < tileCount; j++){ 143 | int gid = tileList.at(j).toElement().attribute("gid").toInt(); 144 | if(gid > 0) { 145 | tiles[tileLength] = gid; 146 | } 147 | tileLength ++; 148 | } 149 | 150 | // Store the gid into a 2d array 151 | for(int spriteForX = 0; spriteForX < mapWidth; spriteForX++) { 152 | for(int spriteForY = 0; spriteForY < mapHeight; spriteForY++) { 153 | int tileGid = tiles[(spriteForX + (spriteForY * mapWidth))]; 154 | tileset * currentTileset; 155 | foreach(tileset *item, map_created -> tilesetVector) { 156 | if(tileGid >= item -> firstGid -1 && tileGid <= item -> lastGid){ 157 | currentTileset = item; 158 | break; 159 | } 160 | } 161 | 162 | int destY = spriteForY * tileWidth; 163 | int destX = spriteForX * tileWidth; 164 | 165 | tileGid -= currentTileset -> firstGid -1; 166 | int sourceY = qFloor( tileGid / currentTileset->tileAmountWidth ); 167 | int sourceX = tileGid - (currentTileset->tileAmountWidth * sourceY) - 1; 168 | 169 | QRect tagmapRect(sourceX * currentTileset->tilewidth, sourceY * currentTileset->tilewidth, currentTileset->tilewidth, currentTileset->tileheight); 170 | QRect sorcmapRect(destX,destY,currentTileset->tilewidth, currentTileset->tileheight); 171 | mapPainter.drawImage(sorcmapRect, currentTileset->image, tagmapRect); 172 | } 173 | } 174 | } 175 | 176 | return this ->markParkingPos(mapImage); 177 | } 178 | 179 | QImage drawMap::draw_widh_nav(QString to_pos_num){ 180 | QImage mapImage = this -> convertXmlToImage(); 181 | // mapImage = this ->markParkingPos(mapImage); 182 | QPainter mapPainter(&mapImage); 183 | mapPainter.setPen(QPen(Qt::red, 4)); 184 | 185 | int x, y, width, height, door_x, door_y, door_width; 186 | 187 | QSqlQuery qry, qry_door; 188 | QString sql = "SELECT * FROM `car_pos` WHERE `pos_num`='" + to_pos_num +"' LIMIT 1"; 189 | qry.prepare(sql); 190 | if( !qry.exec() ){ 191 | qDebug() << qry.lastError(); 192 | exit(0); 193 | } 194 | if( qry.next() ){ 195 | x = qry.value(1).toInt(); 196 | y = qry.value(2).toInt(); 197 | width = qry.value(3).toInt(); 198 | height = qry.value(4).toInt(); 199 | 200 | QString door_pos_sql = "SELECT * FROM `car_pos` WHERE `type`='door' LIMIT 1"; 201 | qry_door.prepare(door_pos_sql); 202 | if( !qry_door.exec() ){ 203 | qDebug() << qry_door.lastError(); 204 | exit(0); 205 | } 206 | if(qry_door.next()) { 207 | door_x = qry_door.value(1).toInt(); 208 | door_y = qry_door.value(2).toInt(); 209 | door_width = qry_door.value(3).toInt(); 210 | } 211 | } 212 | 213 | QPoint *doorPoint = new QPoint(door_x + door_width/2,door_y); 214 | QPoint *centerPoint = new QPoint(door_x + door_width/2, y + height + width/2); 215 | QPoint *targetPoint = new QPoint(x + width/2, y + height + width/2); 216 | QPoint *lastPoint = new QPoint(x + width/2, y + height); 217 | 218 | 219 | mapPainter.drawLine(*doorPoint, *centerPoint); 220 | mapPainter.drawLine(*centerPoint, *targetPoint); 221 | mapPainter.drawLine(*targetPoint, *lastPoint); 222 | 223 | return mapImage; 224 | } 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /drawmap.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWMAP_H 2 | #define DRAWMAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "map.h" 14 | #include "tileset.h" 15 | #include "nav.h" 16 | 17 | class drawMap 18 | { 19 | public: 20 | drawMap(QString xmlFilePath); 21 | void importXmlFile(); 22 | void draw(); 23 | QImage markParkingPos(QImage mapImage); 24 | QImage draw_widh_nav(QString to_pos_num); 25 | QImage convertXmlToImage(); 26 | 27 | private: 28 | QString xmlFilePath; 29 | }; 30 | 31 | #endif // DRAWMAP_H 32 | -------------------------------------------------------------------------------- /in.cpp: -------------------------------------------------------------------------------- 1 | #include "in.h" 2 | #include "ui_in.h" 3 | 4 | in::in(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::in) 7 | { 8 | ui->setupUi(this); 9 | setWindowTitle("停车场管理系统"); 10 | this -> initWindow(); 11 | } 12 | 13 | in::~in() 14 | { 15 | delete ui; 16 | } 17 | 18 | void in::on_back_clicked() 19 | { 20 | MainWindow *m; 21 | m = new MainWindow(); 22 | this -> close(); 23 | m -> show(); 24 | } 25 | 26 | void in::initWindow(){ 27 | 28 | QTimer *timer = new QTimer(this); 29 | displayTime(); 30 | connect(timer, SIGNAL(timeout()), this, SLOT(displayTime())); 31 | timer->start(1000); 32 | 33 | QString car_pos = this -> allocationPos(); 34 | 35 | if(car_pos == "false") { 36 | ui -> pos -> setAlignment(Qt::AlignCenter); 37 | ui -> pos -> setStyleSheet("border: 1px solid red;"); 38 | ui -> pos -> setText("车库已满"); 39 | ui -> car_num -> setEnabled(false); 40 | } else { 41 | ui -> pos -> setAlignment(Qt::AlignCenter); 42 | ui -> pos -> setStyleSheet("border: 1px solid green;"); 43 | ui -> pos -> setText(car_pos); 44 | } 45 | } 46 | 47 | void in::displayTime(){ 48 | QDateTime dt; 49 | QTime time; 50 | QDate date; 51 | 52 | dt.setTime(time.currentTime()); 53 | dt.setDate(date.currentDate()); 54 | 55 | QString currentDate = dt.toString("yyyy-MM-dd hh:mm:ss"); 56 | ui -> in_time -> setAlignment(Qt::AlignCenter); 57 | ui -> in_time -> setStyleSheet("border: 1px solid green;"); 58 | ui->in_time->setText(currentDate); 59 | } 60 | 61 | QString in::allocationPos(){ 62 | // new database(); 63 | 64 | QSqlQuery qry; 65 | qry.prepare( "SELECT * FROM `car_pos` WHERE `status` = 'free' and `type` = 'position' LIMIT 1" ); 66 | if( !qry.exec() ){ 67 | qDebug() << qry.lastError(); 68 | return "DB ERROR"; 69 | } else { 70 | while( qry.next() ){ 71 | return qry.value(0).toString(); 72 | } 73 | return "false"; 74 | } 75 | } 76 | 77 | void in::on_enter_clicked() { 78 | // new database(); 79 | 80 | if(ui -> car_num -> isEnabled()){ 81 | QString input_car_num = ui -> car_num -> text(); 82 | QString input_in_time = ui -> in_time -> text(); 83 | QString input_place_id = ui -> pos -> text(); 84 | 85 | QSqlQuery qry; 86 | QString sql = "INSERT INTO `spaces` (`car_num`, `place_id`, `in_time`) VALUES ('"+ input_car_num +"', '"+ input_place_id +"', '"+ input_in_time +"')"; 87 | 88 | qry.prepare(sql); 89 | 90 | if( !qry.exec() ) { 91 | qDebug() << qry.lastError(); 92 | } else { 93 | QString sql_up = "UPDATE `car_pos` SET `status` = 'full' WHERE id = '"+input_place_id+"'"; 94 | qry.prepare(sql_up); 95 | if( !qry.exec() ) 96 | qDebug() << qry.lastError(); 97 | } 98 | QMessageBox msgBox; 99 | msgBox.setText("入库成功!"); 100 | msgBox.exec(); 101 | this -> initWindow(); 102 | } else { 103 | QMessageBox msgBox; 104 | msgBox.setText("车库已满,不要乱点!!"); 105 | msgBox.exec(); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /in.h: -------------------------------------------------------------------------------- 1 | #ifndef IN_H 2 | #define IN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "mainwindow.h" 11 | #include "database.h" 12 | 13 | namespace Ui { 14 | class in; 15 | } 16 | 17 | class in : public QMainWindow 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit in(QWidget *parent = 0); 23 | ~in(); 24 | 25 | void initWindow(); 26 | QString allocationPos(); 27 | 28 | private slots: 29 | void on_back_clicked(); 30 | void displayTime(); 31 | 32 | void on_enter_clicked(); 33 | 34 | private: 35 | Ui::in *ui; 36 | }; 37 | 38 | #endif // IN_H 39 | -------------------------------------------------------------------------------- /in.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | in 4 | 5 | 6 | 7 | 0 8 | 0 9 | 656 10 | 459 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Droid Sans Fallback 25 | 12 26 | 27 | 28 | 29 | 车牌号: 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | Droid Sans Fallback 38 | 12 39 | 40 | 41 | 42 | 分配车位: 43 | 44 | 45 | 46 | 47 | 48 | 49 | TextLabel 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | Droid Sans Fallback 58 | 12 59 | 60 | 61 | 62 | 进入时间: 63 | 64 | 65 | 66 | 67 | 68 | 69 | TextLabel 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 13 78 | 79 | 80 | 81 | 回主界面 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 12 90 | 91 | 92 | 93 | 确认进入 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | Qt::Horizontal 104 | 105 | 106 | 107 | 40 108 | 20 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 26 118 | 119 | 120 | 121 | Welcome! 122 | 123 | 124 | 125 | 126 | 127 | 128 | Qt::Horizontal 129 | 130 | 131 | 132 | 40 133 | 20 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "database.h" 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | 8 | new database(); // Connect Databse 9 | //new config(); // Load config option 10 | 11 | MainWindow w; 12 | w.show(); 13 | 14 | return a.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::MainWindow) { 7 | ui->setupUi(this); 8 | this -> adminConfig = new config(); 9 | setWindowTitle("停车场管理系统"); 10 | } 11 | 12 | MainWindow::~MainWindow() { 13 | delete ui; 14 | } 15 | 16 | void MainWindow::on_in_clicked() { 17 | in *inWindow; 18 | inWindow = new in(); 19 | this -> close(); 20 | inWindow -> show(); 21 | } 22 | 23 | void MainWindow::on_out_clicked() { 24 | out *outWindow; 25 | outWindow = new out(); 26 | this -> hide(); 27 | outWindow -> show(); 28 | } 29 | 30 | void MainWindow::on_admin_clicked() { 31 | Dialog *loginDialog = new Dialog(); 32 | loginDialog -> show(); 33 | this ->close(); 34 | } 35 | 36 | void MainWindow::on_nav_clicked() { 37 | QString xmlpath = this -> adminConfig ->getConfigOption("xmlpath"); 38 | drawMap *map = new drawMap(xmlpath); 39 | map -> draw(); 40 | } 41 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "in.h" 9 | #include "out.h" 10 | #include "admin.h" 11 | #include "dialog.h" 12 | 13 | 14 | namespace Ui { 15 | class MainWindow; 16 | } 17 | 18 | class MainWindow : public QMainWindow 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit MainWindow(QWidget *parent = 0); 24 | ~MainWindow(); 25 | 26 | private slots: 27 | void on_in_clicked(); 28 | 29 | void on_out_clicked(); 30 | 31 | void on_admin_clicked(); 32 | 33 | void on_nav_clicked(); 34 | 35 | private: 36 | Ui::MainWindow *ui; 37 | config *adminConfig; 38 | }; 39 | 40 | #endif // MAINWINDOW_H 41 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 565 10 | 383 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 20 25 | 26 | 27 | 28 | 进入 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 20 37 | 38 | 39 | 40 | 离开 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 20 49 | 50 | 51 | 52 | 管理 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 20 61 | 62 | 63 | 64 | 导航 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /map.cpp: -------------------------------------------------------------------------------- 1 | #include "map.h" 2 | 3 | map::map(int mapWidth, int mapHeight, int tileWidth, int tileHeight){ 4 | this -> mapWidth = mapWidth; 5 | this -> mapHeight = mapHeight; 6 | this -> tileHeight = tileHeight; 7 | this -> tileWidth = tileWidth; 8 | } 9 | -------------------------------------------------------------------------------- /map.h: -------------------------------------------------------------------------------- 1 | #ifndef MAP_H 2 | #define MAP_H 3 | 4 | #include 5 | #include 6 | 7 | #include "tileset.h" 8 | 9 | class map 10 | { 11 | public: 12 | int mapWidth; 13 | int mapHeight; 14 | int tileWidth; 15 | int tileHeight; 16 | QVector tilesetVector; 17 | 18 | map(int mapWidth, int mapHeight, int tileWidth, int tileHeight); 19 | }; 20 | 21 | #endif // MAP_H 22 | -------------------------------------------------------------------------------- /nav.cpp: -------------------------------------------------------------------------------- 1 | #include "nav.h" 2 | #include "ui_nav.h" 3 | #include 4 | 5 | nav::nav(QWidget *parent) : 6 | QMainWindow(parent), 7 | ui(new Ui::nav) 8 | { 9 | ui->setupUi(this); 10 | setWindowTitle("停车场导航图"); 11 | } 12 | 13 | nav::~nav() 14 | { 15 | delete ui; 16 | } 17 | 18 | void nav::showImage(QImage image){ 19 | label = new QLabel(); 20 | label -> setPixmap(QPixmap::fromImage(image)); 21 | ui -> scrollArea->setWidget(label); 22 | ui -> scrollArea -> setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 23 | ui -> scrollArea ->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); 24 | ui -> scrollArea->viewport()->setBackgroundRole(QPalette::Dark); 25 | this -> show(); 26 | } 27 | 28 | void nav::on_go_clicked() { 29 | QString xmlpath = this -> adminConfig ->getConfigOption("xmlpath"); 30 | QString to_pos_num = ui -> pos_num ->text(); 31 | 32 | drawMap *map = new drawMap(xmlpath); 33 | QImage mapShow = map -> draw_widh_nav(to_pos_num); 34 | this -> showImage(mapShow); 35 | } 36 | -------------------------------------------------------------------------------- /nav.h: -------------------------------------------------------------------------------- 1 | #ifndef NAV_H 2 | #define NAV_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "config.h" 8 | #include "drawmap.h" 9 | #include "mainwindow.h" 10 | 11 | namespace Ui { 12 | class nav; 13 | } 14 | 15 | class nav : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit nav(QWidget *parent = 0); 21 | void showImage(QImage image); 22 | ~nav(); 23 | 24 | private slots: 25 | void on_go_clicked(); 26 | 27 | private: 28 | Ui::nav *ui; 29 | QScrollArea *scrollArea; 30 | QLabel *label; 31 | config *adminConfig; 32 | }; 33 | 34 | #endif // NAV_H 35 | -------------------------------------------------------------------------------- /nav.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | nav 4 | 5 | 6 | 7 | 0 8 | 0 9 | 570 10 | 483 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | Go 27 | 28 | 29 | 30 | 31 | 32 | 33 | true 34 | 35 | 36 | 37 | 38 | 0 39 | 0 40 | 548 41 | 410 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /out.cpp: -------------------------------------------------------------------------------- 1 | #include "out.h" 2 | #include "ui_out.h" 3 | 4 | out::out(QWidget *parent) : 5 | QMainWindow(parent), 6 | ui(new Ui::out) 7 | { 8 | ui->setupUi(this); 9 | setWindowTitle("停车场管理系统"); 10 | this -> initWindow(); 11 | } 12 | 13 | out::~out() 14 | { 15 | delete ui; 16 | } 17 | 18 | void out::on_back_clicked() 19 | { 20 | MainWindow *w; 21 | w = new MainWindow(); 22 | this -> close(); 23 | w -> show(); 24 | } 25 | 26 | void out::initWindow(){ 27 | QTimer *timer = new QTimer(this); 28 | displayTime(); 29 | connect(timer, SIGNAL(timeout()), this, SLOT(displayTime())); 30 | timer->start(1000); 31 | ui -> in_time -> setStyleSheet("border: 1px solid green;"); 32 | ui -> car_pos -> setStyleSheet("border: 1px solid green;"); 33 | ui -> change -> setStyleSheet("border: 1px solid green;"); 34 | } 35 | 36 | void out::displayTime(){ 37 | QDateTime dt; 38 | QTime time; 39 | QDate date; 40 | 41 | dt.setTime(time.currentTime()); 42 | dt.setDate(date.currentDate()); 43 | 44 | QString currentDate = dt.toString("yyyy-MM-dd hh:mm:ss"); 45 | ui -> out_time -> setAlignment(Qt::AlignCenter); 46 | ui -> out_time -> setStyleSheet("border: 1px solid green;"); 47 | ui->out_time->setText(currentDate); 48 | } 49 | 50 | void out::on_textEdit_2_textChanged() 51 | { 52 | QString input_car_num = ui -> textEdit_2 -> text(); 53 | QSqlQuery qry; 54 | QString sql = "SELECT * FROM `spaces` WHERE `car_num`='"+ input_car_num +"' LIMIT 1"; 55 | qry.prepare(sql); 56 | if( !qry.exec() ){ 57 | qDebug() << qry.lastError(); 58 | } else { 59 | if( qry.next() ){ 60 | ui -> car_pos -> setAlignment(Qt::AlignCenter); 61 | ui -> car_pos -> setText(qry.value(2).toString()); 62 | ui -> in_time -> setAlignment(Qt::AlignCenter); 63 | ui -> in_time -> setText(qry.value(3).toString()); 64 | 65 | QTime time; 66 | QDate date; 67 | QDateTime dt = QDateTime::fromString(qry.value(3).toString(),"yyyy-MM-ddThh:mm:ss"); 68 | QDateTime dt_now; 69 | dt_now.setTime(time.currentTime()); 70 | dt_now.setDate(date.currentDate()); 71 | 72 | float should_change = (dt.msecsTo(dt_now) /3600000.0) * 11; 73 | QString tr_timeDiff = QString("%1").arg(should_change); 74 | tr_timeDiff += "元"; 75 | ui -> change -> setAlignment(Qt::AlignCenter); 76 | ui -> change -> setText(tr_timeDiff); 77 | } else { 78 | ui -> car_pos -> setText(""); 79 | ui -> in_time -> setText(""); 80 | ui -> change -> setText(""); 81 | } 82 | } 83 | } 84 | 85 | void out::on_leave_clicked() 86 | { 87 | QString input_car_num = ui -> textEdit_2 -> text(); 88 | QString input_pos_id = ui -> car_pos -> text(); 89 | QSqlQuery qry; 90 | QString sql = "DELETE FROM `spaces` WHERE `car_num` = '"+input_car_num+"'"; 91 | qry.prepare(sql); 92 | if( !qry.exec() ){ 93 | qDebug() << qry.lastError(); 94 | } else { 95 | QString sql_up = "UPDATE `car_pos` SET `status` = 'free' WHERE id = '" + input_pos_id + "'"; 96 | qry.prepare(sql_up); 97 | if( !qry.exec() ){ 98 | qDebug() << qry.lastError(); 99 | } else { 100 | QMessageBox msgBox; 101 | msgBox.setText("出库成功,欢迎下次再来!"); 102 | msgBox.exec(); 103 | ui -> textEdit_2 ->setText(""); 104 | ui -> car_pos -> setText(""); 105 | ui -> in_time -> setText(""); 106 | ui -> change -> setText(""); 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /out.h: -------------------------------------------------------------------------------- 1 | #ifndef OUT_H 2 | #define OUT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "mainwindow.h" 12 | 13 | 14 | namespace Ui { 15 | class out; 16 | } 17 | 18 | class out : public QMainWindow 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit out(QWidget *parent = 0); 24 | ~out(); 25 | void initWindow(); 26 | 27 | private slots: 28 | void on_back_clicked(); 29 | void displayTime(); 30 | 31 | void on_textEdit_2_textChanged(); 32 | 33 | void on_leave_clicked(); 34 | 35 | private: 36 | Ui::out *ui; 37 | }; 38 | 39 | #endif // OUT_H 40 | -------------------------------------------------------------------------------- /out.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | out 4 | 5 | 6 | 7 | 0 8 | 0 9 | 637 10 | 298 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | MainWindow 21 | 22 | 23 | 24 | 25 | 0 26 | 0 27 | 28 | 29 | 30 | Qt::LeftToRight 31 | 32 | 33 | true 34 | 35 | 36 | 37 | 38 | 39 | 20 40 | 41 | 42 | 20 43 | 44 | 45 | 20 46 | 47 | 48 | 20 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Qt::Horizontal 61 | 62 | 63 | 64 | 40 65 | 20 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | Droid Sans Fallback 82 | 12 83 | 84 | 85 | 86 | 进入时间: 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 0 95 | 0 96 | 97 | 98 | 99 | 100 | 13 101 | 102 | 103 | 104 | 回主界面 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Droid Sans Fallback 113 | 12 114 | 115 | 116 | 117 | 车牌号: 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | Droid Sans Fallback 126 | 12 127 | 128 | 129 | 130 | 应付费用: 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | Droid Sans Fallback 139 | 12 140 | 141 | 142 | 143 | 分配车位: 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | Droid Sans Fallback 159 | 12 160 | 161 | 162 | 163 | 离开时间: 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 12 172 | 173 | 174 | 175 | 确认离开 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 26 191 | 192 | 193 | 194 | Thanks! 195 | 196 | 197 | 198 | 199 | 200 | 201 | Qt::Horizontal 202 | 203 | 204 | 205 | 40 206 | 20 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | Qt::Horizontal 215 | 216 | 217 | 218 | 40 219 | 20 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | false 228 | 229 | 230 | 请输入车牌号 231 | 232 | 233 | Qt::AlignCenter 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /parking.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-11-10T17:14:15 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | QT += sql 9 | QT += xml 10 | 11 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 12 | 13 | TARGET = parking 14 | TEMPLATE = app 15 | 16 | 17 | SOURCES += main.cpp\ 18 | mainwindow.cpp \ 19 | in.cpp \ 20 | out.cpp \ 21 | admin.cpp \ 22 | map.cpp \ 23 | drawmap.cpp \ 24 | tileset.cpp \ 25 | nav.cpp \ 26 | config.cpp \ 27 | database.cpp \ 28 | dialog.cpp 29 | 30 | HEADERS += mainwindow.h \ 31 | in.h \ 32 | out.h \ 33 | admin.h \ 34 | map.h \ 35 | drawmap.h \ 36 | tileset.h \ 37 | nav.h \ 38 | config.h \ 39 | database.h \ 40 | dialog.h 41 | 42 | FORMS += mainwindow.ui \ 43 | in.ui \ 44 | out.ui \ 45 | admin.ui \ 46 | nav.ui \ 47 | dialog.ui 48 | -------------------------------------------------------------------------------- /parking.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {13d51cf3-e922-40bc-a581-f9b106ce3970} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | 0 45 | 8 46 | true 47 | 1 48 | true 49 | true 50 | true 51 | false 52 | 53 | 54 | 55 | ProjectExplorer.Project.PluginSettings 56 | 57 | 58 | 59 | ProjectExplorer.Project.Target.0 60 | 61 | Desktop Qt 5.3 GCC 64bit 62 | Desktop Qt 5.3 GCC 64bit 63 | qt.53.gcc_64_kit 64 | 0 65 | 0 66 | 0 67 | 68 | /home/tairy/Documents/parking/build-parking-Desktop_Qt_5_3_GCC_64bit-Debug 69 | 70 | 71 | true 72 | qmake 73 | 74 | QtProjectManager.QMakeBuildStep 75 | false 76 | true 77 | 78 | false 79 | 80 | 81 | true 82 | Make 83 | 84 | Qt4ProjectManager.MakeStep 85 | 86 | -w 87 | -r 88 | 89 | false 90 | -r -w 91 | 92 | 93 | 2 94 | Build 95 | 96 | ProjectExplorer.BuildSteps.Build 97 | 98 | 99 | 100 | true 101 | Make 102 | 103 | Qt4ProjectManager.MakeStep 104 | 105 | -w 106 | -r 107 | 108 | true 109 | -r -w clean 110 | 111 | 112 | 1 113 | Clean 114 | 115 | ProjectExplorer.BuildSteps.Clean 116 | 117 | 2 118 | false 119 | 120 | Debug 121 | 122 | Qt4ProjectManager.Qt4BuildConfiguration 123 | 2 124 | true 125 | 126 | 127 | /home/tairy/Documents/parking/build-parking-Desktop_Qt_5_3_GCC_64bit-Release 128 | 129 | 130 | true 131 | qmake 132 | 133 | QtProjectManager.QMakeBuildStep 134 | false 135 | true 136 | 137 | false 138 | 139 | 140 | true 141 | Make 142 | 143 | Qt4ProjectManager.MakeStep 144 | 145 | -w 146 | -r 147 | 148 | false 149 | -r -w 150 | 151 | 152 | 2 153 | Build 154 | 155 | ProjectExplorer.BuildSteps.Build 156 | 157 | 158 | 159 | true 160 | Make 161 | 162 | Qt4ProjectManager.MakeStep 163 | 164 | -w 165 | -r 166 | 167 | true 168 | -r -w clean 169 | 170 | 171 | 1 172 | Clean 173 | 174 | ProjectExplorer.BuildSteps.Clean 175 | 176 | 2 177 | false 178 | 179 | Release 180 | 181 | Qt4ProjectManager.Qt4BuildConfiguration 182 | 0 183 | true 184 | 185 | 2 186 | 187 | 188 | 0 189 | Deploy 190 | 191 | ProjectExplorer.BuildSteps.Deploy 192 | 193 | 1 194 | Deploy locally 195 | 196 | ProjectExplorer.DefaultDeployConfiguration 197 | 198 | 1 199 | 200 | 201 | 202 | false 203 | false 204 | false 205 | false 206 | true 207 | 0.01 208 | 10 209 | true 210 | 1 211 | 25 212 | 213 | 1 214 | true 215 | false 216 | true 217 | valgrind 218 | 219 | 0 220 | 1 221 | 2 222 | 3 223 | 4 224 | 5 225 | 6 226 | 7 227 | 8 228 | 9 229 | 10 230 | 11 231 | 12 232 | 13 233 | 14 234 | 235 | 2 236 | 237 | parking 238 | 239 | Qt4ProjectManager.Qt4RunConfiguration:/home/tairy/Documents/parking/parking/parking.pro 240 | 241 | parking.pro 242 | false 243 | false 244 | 245 | 3768 246 | false 247 | true 248 | false 249 | false 250 | true 251 | 252 | 1 253 | 254 | 255 | 256 | ProjectExplorer.Project.TargetCount 257 | 1 258 | 259 | 260 | ProjectExplorer.Project.Updater.FileVersion 261 | 16 262 | 263 | 264 | Version 265 | 16 266 | 267 | 268 | -------------------------------------------------------------------------------- /parking.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.2.11 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: localhost 6 | -- Generation Time: Nov 22, 2014 at 02:49 PM 7 | -- Server version: 5.5.40-0ubuntu0.12.04.1 8 | -- PHP Version: 5.3.10-1ubuntu3.15 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | 19 | -- 20 | -- Database: `parking` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `car_pos` 27 | -- 28 | 29 | CREATE TABLE IF NOT EXISTS `car_pos` ( 30 | `id` int(11) NOT NULL, 31 | `x` int(11) NOT NULL, 32 | `y` int(11) NOT NULL, 33 | `width` int(11) NOT NULL, 34 | `height` int(11) NOT NULL, 35 | `status` varchar(45) NOT NULL, 36 | `type` varchar(255) NOT NULL, 37 | `pos_num` int(11) NOT NULL 38 | ) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=latin1; 39 | 40 | -- 41 | -- Dumping data for table `car_pos` 42 | -- 43 | 44 | INSERT INTO `car_pos` (`id`, `x`, `y`, `width`, `height`, `status`, `type`, `pos_num`) VALUES 45 | (1, 0, 0, 64, 96, 'full', 'position', 1), 46 | (2, 192, 0, 64, 96, 'free', 'position', 2), 47 | (3, 128, 0, 64, 96, 'free', 'position', 3), 48 | (4, 64, 0, 64, 96, 'free', 'position', 4), 49 | (5, 256, 0, 64, 96, 'free', 'position', 5), 50 | (6, 320, 0, 64, 96, 'free', 'position', 6), 51 | (7, 384, 0, 64, 96, 'free', 'position', 7), 52 | (8, 448, 0, 64, 96, 'free', 'position', 8), 53 | (9, 576, 0, 64, 96, 'free', 'position', 9), 54 | (10, 512, 0, 64, 96, 'free', 'position', 10), 55 | (11, 256, 160, 64, 96, 'free', 'position', 11), 56 | (12, 0, 160, 64, 96, 'free', 'position', 12), 57 | (13, 64, 160, 64, 96, 'free', 'position', 13), 58 | (14, 192, 160, 64, 96, 'free', 'position', 14), 59 | (15, 128, 160, 64, 96, 'free', 'position', 15), 60 | (16, 576, 160, 64, 96, 'free', 'position', 16), 61 | (17, 512, 160, 64, 96, 'free', 'position', 17), 62 | (18, 448, 160, 64, 96, 'free', 'position', 18), 63 | (19, 384, 160, 64, 96, 'free', 'position', 19), 64 | (20, 64, 320, 64, 96, 'free', 'position', 20), 65 | (21, 0, 320, 64, 96, 'free', 'position', 21), 66 | (22, 128, 320, 64, 96, 'free', 'position', 22), 67 | (23, 192, 320, 64, 96, 'free', 'position', 23), 68 | (24, 256, 320, 64, 96, 'free', 'position', 24), 69 | (25, 64, 480, 64, 96, 'free', 'position', 25), 70 | (26, 0, 480, 64, 96, 'free', 'position', 26), 71 | (27, 128, 480, 64, 96, 'free', 'position', 27), 72 | (28, 192, 480, 64, 96, 'free', 'position', 28), 73 | (29, 256, 480, 64, 96, 'free', 'position', 29), 74 | (30, 579, 320, 64, 96, 'free', 'position', 30), 75 | (31, 387, 320, 64, 96, 'free', 'position', 31), 76 | (32, 515, 320, 64, 96, 'free', 'position', 32), 77 | (33, 451, 320, 64, 96, 'free', 'position', 33), 78 | (34, 576, 480, 64, 96, 'free', 'position', 34), 79 | (35, 448, 480, 64, 96, 'free', 'position', 35), 80 | (36, 384, 480, 64, 96, 'free', 'position', 36), 81 | (37, 512, 480, 64, 96, 'free', 'position', 37), 82 | (38, 320, 608, 64, 32, 'free', 'door', 38); 83 | 84 | -- -------------------------------------------------------- 85 | 86 | -- 87 | -- Table structure for table `config` 88 | -- 89 | 90 | CREATE TABLE IF NOT EXISTS `config` ( 91 | `id` int(11) NOT NULL, 92 | `key` varchar(255) NOT NULL, 93 | `value` varchar(255) NOT NULL 94 | ) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=latin1; 95 | 96 | -- 97 | -- Dumping data for table `config` 98 | -- 99 | 100 | INSERT INTO `config` (`id`, `key`, `value`) VALUES 101 | (1, 'maploaded', 'true'), 102 | (2, 'maploaded', 'true'), 103 | (3, 'maploaded', 'true'), 104 | (4, 'maploaded', 'true'), 105 | (5, 'maploaded', 'true'), 106 | (6, 'maploaded', 'true'), 107 | (7, 'maploaded', 'true'), 108 | (8, 'maploaded', 'true'), 109 | (9, 'maploaded', 'true'), 110 | (10, 'maploaded', 'true'), 111 | (11, 'maploaded', 'true'), 112 | (12, 'maploaded', 'true'), 113 | (13, 'maploaded', 'true'), 114 | (14, 'maploaded', 'true'), 115 | (15, 'maploaded', 'true'), 116 | (16, 'maploaded', 'true'), 117 | (17, 'maploaded', 'true'), 118 | (18, 'maploaded', 'true'), 119 | (19, 'maploaded', 'true'), 120 | (20, 'maploaded', 'true'), 121 | (21, 'maploaded', 'true'), 122 | (22, 'maploaded', 'true'), 123 | (23, 'maploaded', 'true'), 124 | (24, 'maploaded', 'true'), 125 | (25, 'maploaded', 'true'), 126 | (26, 'maploaded', 'true'), 127 | (27, 'maploaded', 'true'), 128 | (28, 'maploaded', 'true'), 129 | (29, 'maploaded', 'true'), 130 | (30, 'maploaded', 'true'), 131 | (31, 'maploaded', 'true'), 132 | (32, 'maploaded', 'true'), 133 | (33, 'maploaded', 'true'), 134 | (34, 'maploaded', 'true'), 135 | (35, 'maploaded', 'true'), 136 | (36, 'maploaded', 'true'), 137 | (37, 'maploaded', 'true'), 138 | (38, 'maploaded', 'true'), 139 | (39, 'xmlpath', '/home/tairy/Documents/test.xml'); 140 | 141 | -- -------------------------------------------------------- 142 | 143 | -- 144 | -- Table structure for table `spaces` 145 | -- 146 | 147 | CREATE TABLE IF NOT EXISTS `spaces` ( 148 | `id` int(11) NOT NULL, 149 | `car_num` varchar(255) CHARACTER SET utf8 NOT NULL, 150 | `place_id` int(11) NOT NULL, 151 | `in_time` datetime NOT NULL 152 | ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1; 153 | 154 | -- 155 | -- Dumping data for table `spaces` 156 | -- 157 | 158 | INSERT INTO `spaces` (`id`, `car_num`, `place_id`, `in_time`) VALUES 159 | (1, '2', 1, '0000-00-00 00:00:00'), 160 | (2, '111111', 2, '2014-11-11 19:34:42'), 161 | (3, '111111', 2, '2014-11-11 19:39:32'), 162 | (4, '111111', 1, '2014-11-11 19:53:12'), 163 | (5, '请输入你的车牌号!', 0, '2014-11-11 20:00:01'), 164 | (6, 'hahsh', 1, '2014-11-11 20:03:04'), 165 | (7, 'test', 1, '2014-11-11 20:05:04'), 166 | (11, 'sds', 1, '2014-11-11 20:08:57'), 167 | (12, 'dd', 1, '2014-11-11 20:10:56'), 168 | (13, '请输入你的车牌号!', 1, '2014-11-13 19:50:59'), 169 | (14, 'dada', 2, '2014-11-13 21:04:34'), 170 | (16, 'Assss', 1, '2014-11-21 14:41:09'); 171 | 172 | -- -------------------------------------------------------- 173 | 174 | -- 175 | -- Table structure for table `user` 176 | -- 177 | 178 | CREATE TABLE IF NOT EXISTS `user` ( 179 | `id` int(11) NOT NULL, 180 | `username` varchar(255) NOT NULL, 181 | `password` varchar(255) NOT NULL 182 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; 183 | 184 | -- 185 | -- Dumping data for table `user` 186 | -- 187 | 188 | INSERT INTO `user` (`id`, `username`, `password`) VALUES 189 | (1, 'admin', 'admin'); 190 | 191 | -- 192 | -- Indexes for dumped tables 193 | -- 194 | 195 | -- 196 | -- Indexes for table `car_pos` 197 | -- 198 | ALTER TABLE `car_pos` 199 | ADD PRIMARY KEY (`id`); 200 | 201 | -- 202 | -- Indexes for table `config` 203 | -- 204 | ALTER TABLE `config` 205 | ADD PRIMARY KEY (`id`); 206 | 207 | -- 208 | -- Indexes for table `spaces` 209 | -- 210 | ALTER TABLE `spaces` 211 | ADD PRIMARY KEY (`id`); 212 | 213 | -- 214 | -- Indexes for table `user` 215 | -- 216 | ALTER TABLE `user` 217 | ADD PRIMARY KEY (`id`); 218 | 219 | -- 220 | -- AUTO_INCREMENT for dumped tables 221 | -- 222 | 223 | -- 224 | -- AUTO_INCREMENT for table `car_pos` 225 | -- 226 | ALTER TABLE `car_pos` 227 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=39; 228 | -- 229 | -- AUTO_INCREMENT for table `config` 230 | -- 231 | ALTER TABLE `config` 232 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=40; 233 | -- 234 | -- AUTO_INCREMENT for table `spaces` 235 | -- 236 | ALTER TABLE `spaces` 237 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=19; 238 | -- 239 | -- AUTO_INCREMENT for table `user` 240 | -- 241 | ALTER TABLE `user` 242 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2; 243 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 244 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 245 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 246 | -------------------------------------------------------------------------------- /tileset.cpp: -------------------------------------------------------------------------------- 1 | #include "tileset.h" 2 | 3 | tileset::tileset(int imageWidth, int imageHeight, int firstGid, int tilewidth, int tileheight, QString source, QString name){ 4 | this -> imageWidth = imageWidth; 5 | this -> imageHeight = imageHeight; 6 | this -> firstGid = firstGid; 7 | this -> tilewidth = tilewidth; 8 | this -> tileheight = tileheight; 9 | this -> source = source; 10 | this -> name = name; 11 | this -> tileAmountWidth = qFloor(imageWidth / tilewidth); 12 | this -> lastGid = tileAmountWidth * qFloor(imageHeight / tileheight) + firstGid - 1; 13 | QString imagePath = "/home/tairy/Documents/" + this -> source; 14 | this -> image = QImage(imagePath); 15 | } 16 | -------------------------------------------------------------------------------- /tileset.h: -------------------------------------------------------------------------------- 1 | #ifndef TILESET_H 2 | #define TILESET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class tileset 11 | { 12 | public: 13 | tileset(int imageWidth, int imageHeight, int firstGid, int tilewidth, int tileheight, QString source, QString name); 14 | 15 | int imageWidth; 16 | int imageHeight; 17 | int firstGid; 18 | int lastGid; 19 | int tilewidth; 20 | int tileheight; 21 | int tileAmountWidth; 22 | QString source; 23 | QString name; 24 | QImage image; 25 | }; 26 | 27 | #endif // TILESET_H 28 | --------------------------------------------------------------------------------