commit
f7a7a0443a
12 changed files with 1108 additions and 0 deletions
@ -0,0 +1,57 @@ |
|||||
|
# C++ objects and libs |
||||
|
*.slo |
||||
|
*.lo |
||||
|
*.o |
||||
|
*.a |
||||
|
*.la |
||||
|
*.lai |
||||
|
*.so |
||||
|
*.dll |
||||
|
*.dylib |
||||
|
|
||||
|
# Qt-es |
||||
|
object_script.*.Release |
||||
|
object_script.*.Debug |
||||
|
*_plugin_import.cpp |
||||
|
/.qmake.cache |
||||
|
/.qmake.stash |
||||
|
*.pro.user |
||||
|
*.pro.user.* |
||||
|
*.qbs.user |
||||
|
*.qbs.user.* |
||||
|
*.moc |
||||
|
moc_*.cpp |
||||
|
moc_*.h |
||||
|
qrc_*.cpp |
||||
|
ui_*.h |
||||
|
*.qmlc |
||||
|
*.jsc |
||||
|
Makefile* |
||||
|
*build-* |
||||
|
|
||||
|
# Qt unit tests |
||||
|
target_wrapper.* |
||||
|
|
||||
|
# QtCreator |
||||
|
*.autosave |
||||
|
|
||||
|
# QtCreator Qml |
||||
|
*.qmlproject.user |
||||
|
*.qmlproject.user.* |
||||
|
|
||||
|
# QtCreator CMake |
||||
|
CMakeLists.txt.user* |
||||
|
|
||||
|
# QtCreator 4.8< compilation database |
||||
|
compile_commands.json |
||||
|
|
||||
|
# QtCreator local machine specific files for imported projects |
||||
|
*creator.user* |
||||
|
|
||||
|
#added be H-4nd-H to the template to comply with project needs |
||||
|
|
||||
|
*.pro.dummy |
||||
|
|
||||
|
bin/ |
||||
|
doc/ |
||||
|
*.lupdate |
@ -0,0 +1,36 @@ |
|||||
|
QT += core gui |
||||
|
QT += xml |
||||
|
|
||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets |
||||
|
|
||||
|
CONFIG += c++11 |
||||
|
|
||||
|
# The following define makes your compiler emit warnings if you use |
||||
|
# any Qt feature that has been marked deprecated (the exact warnings |
||||
|
# depend on your compiler). Please consult the documentation of the |
||||
|
# deprecated API in order to know how to port your code away from it. |
||||
|
DEFINES += QT_DEPRECATED_WARNINGS |
||||
|
|
||||
|
# You can also make your code fail to compile if it uses deprecated APIs. |
||||
|
# In order to do so, uncomment the following line. |
||||
|
# You can also select to disable deprecated APIs only up to a certain version of Qt. |
||||
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 |
||||
|
|
||||
|
SOURCES += \ |
||||
|
main.cpp \ |
||||
|
mainwindow.cpp |
||||
|
|
||||
|
HEADERS += \ |
||||
|
mainwindow.h \ |
||||
|
state.h |
||||
|
|
||||
|
FORMS += \ |
||||
|
mainwindow.ui |
||||
|
|
||||
|
# Default rules for deployment. |
||||
|
qnx: target.path = /tmp/$${TARGET}/bin |
||||
|
else: unix:!android: target.path = /opt/$${TARGET}/bin |
||||
|
!isEmpty(target.path): INSTALLS += target |
||||
|
|
||||
|
RESOURCES += \ |
||||
|
res/Icons.qrc |
@ -0,0 +1,11 @@ |
|||||
|
#include "mainwindow.h" |
||||
|
|
||||
|
#include <QApplication> |
||||
|
|
||||
|
int main(int argc, char *argv[]) |
||||
|
{ |
||||
|
QApplication a(argc, argv); |
||||
|
MainWindow w; |
||||
|
w.show(); |
||||
|
return a.exec(); |
||||
|
} |
@ -0,0 +1,592 @@ |
|||||
|
#include <QFileDialog> |
||||
|
#include "mainwindow.h" |
||||
|
#include "ui_mainwindow.h" |
||||
|
#include "state.h" |
||||
|
|
||||
|
MainWindow::MainWindow(QWidget *parent) |
||||
|
: QMainWindow(parent) |
||||
|
, ui(new Ui::MainWindow) |
||||
|
{ |
||||
|
ui->setupUi(this); |
||||
|
|
||||
|
//create model
|
||||
|
hideWidgets(); |
||||
|
_model = new QStandardItemModel(0,1,this); |
||||
|
ui->treeView->setModel(_model); |
||||
|
} |
||||
|
|
||||
|
MainWindow::~MainWindow() |
||||
|
{ |
||||
|
delete ui; |
||||
|
} |
||||
|
|
||||
|
void MainWindow::readFile() |
||||
|
{ |
||||
|
_model->clear(); |
||||
|
QStandardItem *root = new QStandardItem("root:Root"); |
||||
|
_model->appendRow(root); |
||||
|
|
||||
|
QDomDocument document; |
||||
|
|
||||
|
//load file
|
||||
|
QFile file(_fileName); |
||||
|
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) |
||||
|
{ |
||||
|
document.setContent(&file); |
||||
|
file.close(); |
||||
|
} |
||||
|
|
||||
|
//read xml file
|
||||
|
QDomElement xmlroot = document.firstChildElement(); |
||||
|
|
||||
|
QDomNodeList Databases = xmlroot.elementsByTagName("Database"); |
||||
|
for (int i = 0; i < Databases.count(); ++i) |
||||
|
{ |
||||
|
QDomElement database= Databases.at(i).toElement(); |
||||
|
_DBElementVector.append(database); |
||||
|
_DBNameVector.append(database.attribute("name")); |
||||
|
QStandardItem *databaseItem = new QStandardItem(QString("DB : %1").arg(database.attribute("name"))); |
||||
|
|
||||
|
//read tables
|
||||
|
QDomNodeList tables = database.elementsByTagName("Table"); |
||||
|
for (int t = 0; t < tables.count(); ++t) |
||||
|
{ |
||||
|
QDomElement table = tables.at(t).toElement(); |
||||
|
QStandardItem *tableItem = new QStandardItem(QString("TBL : %1").arg(table.attribute("name"))); |
||||
|
|
||||
|
//read Field
|
||||
|
QDomNodeList fields = table.elementsByTagName("Field"); |
||||
|
for (int f = 0; f < fields.count(); ++f) |
||||
|
{ |
||||
|
QDomElement field = fields.at(f).toElement(); |
||||
|
QStandardItem *fieldItem = new QStandardItem(QString("FLD : %1").arg(field.attribute("name"))); |
||||
|
// "Name: "+field.attribute("name") + "; Type: " + field.attribute("type") + "; Allow Null: " + field.attribute("null") + "; Is Forign key:" + field.attribute("isforeignkey"));
|
||||
|
|
||||
|
tableItem->appendRow(fieldItem); |
||||
|
} |
||||
|
databaseItem->appendRow(tableItem); |
||||
|
} |
||||
|
root->appendRow(databaseItem); |
||||
|
} |
||||
|
_xmlDoc = document; |
||||
|
} |
||||
|
|
||||
|
void MainWindow::readFile(QDomDocument xmlInput) |
||||
|
{ |
||||
|
_model->clear(); |
||||
|
QStandardItem *root = new QStandardItem("root:Root"); |
||||
|
_model->appendRow(root); |
||||
|
|
||||
|
QDomDocument document; |
||||
|
document = xmlInput; |
||||
|
|
||||
|
//read xml file
|
||||
|
QDomElement xmlroot = document.firstChildElement(); |
||||
|
|
||||
|
QDomNodeList Databases = xmlroot.elementsByTagName("Database"); |
||||
|
for (int i = 0; i < Databases.count(); ++i) |
||||
|
{ |
||||
|
QDomElement database= Databases.at(i).toElement(); |
||||
|
QStandardItem *databaseItem = new QStandardItem(QString("DB : %1").arg(database.attribute("name"))); |
||||
|
|
||||
|
//read tables
|
||||
|
QDomNodeList tables = database.elementsByTagName("Table"); |
||||
|
for (int t = 0; t < tables.count(); ++t) |
||||
|
{ |
||||
|
QDomElement table = tables.at(t).toElement(); |
||||
|
QStandardItem *tableItem = new QStandardItem(QString("TBL : %1").arg(table.attribute("name"))); |
||||
|
|
||||
|
//read Field
|
||||
|
QDomNodeList fields = table.elementsByTagName("Field"); |
||||
|
for (int f = 0; f < fields.count(); ++f) |
||||
|
{ |
||||
|
QDomElement field = fields.at(f).toElement(); |
||||
|
QStandardItem *fieldItem = new QStandardItem(QString("FLD : %1").arg(field.attribute("name"))); |
||||
|
// "Name: "+field.attribute("name") + "; Type: " + field.attribute("type") + "; Allow Null: " + field.attribute("null") + "; Is Forign key:" + field.attribute("isforeignkey"));
|
||||
|
|
||||
|
tableItem->appendRow(fieldItem); |
||||
|
} |
||||
|
databaseItem->appendRow(tableItem); |
||||
|
} |
||||
|
root->appendRow(databaseItem); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void MainWindow::writeFile() |
||||
|
{ |
||||
|
_fileName = QFileDialog::getSaveFileName(this); |
||||
|
QFile savefile(_fileName); |
||||
|
if(!savefile.open(QIODevice::WriteOnly | QIODevice::Text)) |
||||
|
{ |
||||
|
qDebug()<< "Ops! can not create file"; |
||||
|
} |
||||
|
QTextStream stream(&savefile); |
||||
|
stream<<_xmlDoc.toString(); |
||||
|
savefile.close(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
void MainWindow::on_actionCreate_Database_triggered() |
||||
|
{ |
||||
|
hideWidgets(); |
||||
|
_state = eStateLevel::createDatabase; |
||||
|
if(_xmlDoc.isNull()) |
||||
|
{ |
||||
|
_root = _xmlDoc.createElement("Root"); |
||||
|
_xmlDoc.appendChild(_root); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_root = _xmlDoc.firstChild().toElement(); |
||||
|
} |
||||
|
|
||||
|
readFile(_xmlDoc); |
||||
|
|
||||
|
|
||||
|
ui->label_1->setText("Database Name"); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->show(); |
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_actionAdd_Table_triggered() |
||||
|
{ |
||||
|
|
||||
|
if(!_xmlDoc.isNull()) |
||||
|
{ |
||||
|
hideWidgets(); |
||||
|
_state = eStateLevel::createTable; |
||||
|
ui->label_1->setText("Table Name"); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->show(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_actionAdd_Field_triggered() |
||||
|
{ |
||||
|
|
||||
|
if(!_xmlDoc.isNull() /*&& !_lastDBElement.isNull()*/) |
||||
|
{ |
||||
|
hideWidgets(); |
||||
|
_state = eStateLevel::createField; |
||||
|
ui->label_1->setText("Field Name :"); |
||||
|
ui->cmbType->show(); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->show(); |
||||
|
ui->chbIsNull->show(); |
||||
|
ui->chbIsForignKey->show(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_chbIsForignKey_stateChanged(int arg1) |
||||
|
{ |
||||
|
if(arg1 > 0) |
||||
|
{ |
||||
|
ui->cmbTablsName->addItem(""); |
||||
|
for (int i = 0; i < _lastDBElement.childNodes().count(); ++i) |
||||
|
{ |
||||
|
auto tblElem = _lastDBElement.childNodes().at(i); |
||||
|
ui->cmbTablsName->addItem(tblElem.toElement().attribute("name")); |
||||
|
} |
||||
|
ui->cmbTablsName->show(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
ui->cmbTablsName->hide(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void MainWindow::hideWidgets() |
||||
|
{ |
||||
|
ui->label_1->hide(); |
||||
|
ui->label_2->hide(); |
||||
|
ui->label_3->hide(); |
||||
|
ui->label_4->hide(); |
||||
|
|
||||
|
ui->lineEdit_1->hide(); |
||||
|
ui->lineEdit_2->hide(); |
||||
|
ui->lineEdit_3->hide(); |
||||
|
ui->lineEdit_4->hide(); |
||||
|
|
||||
|
ui->Append_btn->setText("Append"); |
||||
|
ui->Append_btn->hide(); |
||||
|
|
||||
|
ui->cmbType->hide(); |
||||
|
ui->chbIsNull->hide(); |
||||
|
ui->chbIsForignKey->hide(); |
||||
|
ui->cmbTablsName->hide(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_Append_btn_clicked() |
||||
|
{ |
||||
|
switch (_state) |
||||
|
{ |
||||
|
case eStateLevel::createDatabase: |
||||
|
{ |
||||
|
_lastDBElement =_xmlDoc.createElement("Database"); |
||||
|
auto dbName = ui->lineEdit_1->text(); |
||||
|
_lastDBElement.setAttribute("name",dbName); |
||||
|
_DBElementVector.append(_lastDBElement); |
||||
|
_root.appendChild(_lastDBElement); |
||||
|
_xmlDoc.childNodes().at(0) = _root; |
||||
|
readFile(_xmlDoc); |
||||
|
hideWidgets(); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
break; |
||||
|
} |
||||
|
case eStateLevel::createTable: |
||||
|
{ |
||||
|
_lastTableElement = _xmlDoc.createElement("Table"); |
||||
|
auto tableName = ui->lineEdit_1->text(); |
||||
|
_lastTableElement.setAttribute("name",tableName); |
||||
|
_lastDBElement.appendChild(_lastTableElement); |
||||
|
readFile(_xmlDoc); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
hideWidgets(); |
||||
|
break; |
||||
|
} |
||||
|
case eStateLevel::createField: |
||||
|
{ |
||||
|
if(_lastTableElement.isNull() || _lastDBElement.isNull()) |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please select Database and Table"
|
||||
|
break; |
||||
|
} |
||||
|
if(ui->lineEdit_1->text() == "") |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please set the field name"
|
||||
|
break; |
||||
|
} |
||||
|
auto a = ui->cmbType->currentIndex(); |
||||
|
if(a < 1) |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please set the Type"
|
||||
|
break; |
||||
|
} |
||||
|
auto fieldName = ui->lineEdit_1->text(); |
||||
|
auto field = _xmlDoc.createElement("Field"); |
||||
|
field.setAttribute("name",fieldName); |
||||
|
if(ui->cmbType->currentText() == "VARCHAR") |
||||
|
{ |
||||
|
field.setAttribute("type",QString("%1(%2)").arg(ui->cmbType->currentText()).arg(ui->lineEdit_2->text())); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
field.setAttribute("type",ui->cmbType->currentText()); |
||||
|
} |
||||
|
if(ui->chbIsNull->checkState() == Qt::CheckState::Unchecked) |
||||
|
field.setAttribute("null","NOT"); |
||||
|
if(ui->chbIsForignKey->checkState() == Qt::CheckState::Checked) |
||||
|
{ |
||||
|
field.setAttribute("isforeignkey","true"); |
||||
|
field.setAttribute("lookuptable",ui->cmbTablsName->currentText()); |
||||
|
field.setAttribute("lookuptable","ID"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
field.setAttribute("isforeignkey","false"); |
||||
|
} |
||||
|
|
||||
|
_lastTableElement.appendChild(field); |
||||
|
|
||||
|
readFile(_xmlDoc); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
hideWidgets(); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
case eStateLevel::editDatabase: |
||||
|
{ |
||||
|
|
||||
|
auto oldDB = _lastDBElement; |
||||
|
_lastDBElement.setAttribute("name",ui->lineEdit_1->text()); |
||||
|
auto root = _xmlDoc.firstChildElement().replaceChild(_lastDBElement,oldDB); |
||||
|
readFile(_xmlDoc); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
hideWidgets(); |
||||
|
break; |
||||
|
} |
||||
|
case eStateLevel::editTable: |
||||
|
{ |
||||
|
|
||||
|
auto oldTbl = _lastTableElement; |
||||
|
_lastTableElement.setAttribute("name",ui->lineEdit_1->text()); |
||||
|
auto root = _lastDBElement.replaceChild(_lastTableElement,oldTbl); |
||||
|
readFile(_xmlDoc); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
hideWidgets(); |
||||
|
break; |
||||
|
} |
||||
|
case eStateLevel::editField: |
||||
|
{ |
||||
|
if(_lastTableElement.isNull() || _lastDBElement.isNull()) |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please select Database and Table"
|
||||
|
break; |
||||
|
} |
||||
|
if(ui->lineEdit_1->text() == "") |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please set the field name"
|
||||
|
break; |
||||
|
} |
||||
|
auto a = ui->cmbType->currentIndex(); |
||||
|
if(a < 1) |
||||
|
{ |
||||
|
//TODO :: show mesagebox Text "Please set the Type"
|
||||
|
break; |
||||
|
} |
||||
|
auto fieldName = ui->lineEdit_1->text(); |
||||
|
auto field = _xmlDoc.createElement("Field"); |
||||
|
field.setAttribute("name",fieldName); |
||||
|
if(ui->cmbType->currentText() == "VARCHAR") |
||||
|
{ |
||||
|
field.setAttribute("type",QString("%1(%2)").arg(ui->cmbType->currentText()).arg(ui->lineEdit_2->text())); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
field.setAttribute("type",ui->cmbType->currentText()); |
||||
|
} |
||||
|
if(ui->chbIsNull->checkState() == Qt::CheckState::Unchecked) |
||||
|
field.setAttribute("null","NOT"); |
||||
|
if(ui->chbIsForignKey->checkState() == Qt::CheckState::Checked) |
||||
|
{ |
||||
|
field.setAttribute("isforeignkey","true"); |
||||
|
field.setAttribute("lookuptable",ui->cmbTablsName->currentText()); |
||||
|
field.setAttribute("lookuptable","ID"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
field.setAttribute("isforeignkey","false"); |
||||
|
} |
||||
|
auto oldFld = _lastFieldElement; |
||||
|
_lastTableElement.replaceChild(field,oldFld); |
||||
|
|
||||
|
readFile(_xmlDoc); |
||||
|
ui->lineEdit_1->setText(""); |
||||
|
hideWidgets(); |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
default: |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
void MainWindow::on_cmbTablsName_currentIndexChanged(int index) |
||||
|
{ |
||||
|
if(ui->chbIsForignKey->checkState() == Qt::CheckState::Checked) |
||||
|
{ |
||||
|
if(index > 0 ) |
||||
|
{ |
||||
|
ui->lineEdit_1->setText(QString("%1_id").arg(ui->cmbTablsName->currentText())); |
||||
|
ui->cmbType->setCurrentIndex(1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_treeView_doubleClicked(const QModelIndex &index) |
||||
|
{ |
||||
|
hideWidgets(); |
||||
|
auto type = getElementType(index); |
||||
|
switch (type) |
||||
|
{ |
||||
|
case MainWindow::eElementType::root : |
||||
|
{ |
||||
|
break; |
||||
|
} |
||||
|
case MainWindow::eElementType::database : |
||||
|
{ |
||||
|
_state = MainWindow::eStateLevel::editDatabase; |
||||
|
for (int i = 0; i < _xmlDoc.firstChild().childNodes().count(); ++i) |
||||
|
{ |
||||
|
if( _xmlDoc.firstChild().childNodes().at(i).toElement().attribute("name") == index.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
|
||||
|
_lastDBElement = _xmlDoc.firstChild().childNodes().at(i).toElement(); |
||||
|
ui->label_1->setText("Database Name: "); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->setText(_xmlDoc.firstChild().childNodes().at(i).toElement().attribute("name")); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->setText("edit"); |
||||
|
ui->Append_btn->show(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
// _lastDBElement.clear();
|
||||
|
break; |
||||
|
} |
||||
|
case MainWindow::eElementType::table : |
||||
|
{ |
||||
|
_state = MainWindow::eStateLevel::editTable; |
||||
|
auto database = index.parent(); |
||||
|
_lastDBElement.clear(); |
||||
|
for (int i = 0; i < _xmlDoc.firstChild().childNodes().count(); ++i) |
||||
|
{ |
||||
|
if(_xmlDoc.firstChild().childNodes().at(i).toElement().attribute("name") == database.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
_lastDBElement = _xmlDoc.firstChild().childNodes().at(i).toElement(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
for (int i = 0; i < _lastDBElement.childNodes().count(); ++i) |
||||
|
{ |
||||
|
auto tblItem = _lastDBElement.childNodes().at(i); |
||||
|
_lastTableElement.clear(); |
||||
|
auto elem = tblItem.toElement(); |
||||
|
if(elem.attribute("name") == index.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
_lastTableElement = elem; |
||||
|
ui->label_1->setText("Table Name: "); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->setText(elem.attribute("name")); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->setText("edit"); |
||||
|
ui->Append_btn->show(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
case MainWindow::eElementType::field : |
||||
|
{ |
||||
|
_state = MainWindow::eStateLevel::editField; |
||||
|
auto table = index.parent(); |
||||
|
auto database = table.parent(); |
||||
|
_lastDBElement.clear(); |
||||
|
for (int i = 0; i < _xmlDoc.firstChild().childNodes().count(); ++i) |
||||
|
{ |
||||
|
if(_xmlDoc.firstChild().childNodes().at(i).toElement().attribute("name") == database.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
_lastDBElement = _xmlDoc.firstChild().childNodes().at(i).toElement(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
for (int i = 0; i < _lastDBElement.childNodes().count(); ++i) |
||||
|
{ |
||||
|
auto tblelem = _lastDBElement.childNodes().at(i).toElement(); |
||||
|
_lastTableElement.clear(); |
||||
|
if(tblelem.attribute("name") == table.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
_lastTableElement = tblelem; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
for (int i = 0; i < _lastTableElement.childNodes().count(); ++i) |
||||
|
{ |
||||
|
_lastFieldElement = _lastTableElement.childNodes().at(i).toElement(); |
||||
|
if(_lastFieldElement.attribute("name") == index.data().toString().split(" : ").at(1)) |
||||
|
{ |
||||
|
ui->label_1->setText("Field Name: "); |
||||
|
ui->label_1->show(); |
||||
|
ui->lineEdit_1->setText(_lastFieldElement.attribute("name")); |
||||
|
ui->lineEdit_1->show(); |
||||
|
ui->Append_btn->setText("edit"); |
||||
|
if(_lastFieldElement.attribute("type") == "INTEGER") |
||||
|
ui->cmbType->setCurrentText("INT"); |
||||
|
else if(_lastFieldElement.attribute("type").toLower().contains("varchar")) |
||||
|
{ |
||||
|
ui->cmbType->setCurrentText("VARCHAR"); |
||||
|
auto size = _lastFieldElement.attribute("type").toLower().split("(").at(1); |
||||
|
size.replace(")",""); |
||||
|
ui->lineEdit_2->setText(size); |
||||
|
ui->lineEdit_2->show(); |
||||
|
} |
||||
|
else |
||||
|
ui->cmbType->setCurrentText(_lastFieldElement.attribute("type")); |
||||
|
|
||||
|
ui->cmbType->show(); |
||||
|
if(_lastFieldElement.attribute("null") == "NOT") |
||||
|
ui->chbIsNull->setCheckState(Qt::CheckState::Unchecked); |
||||
|
else |
||||
|
{ |
||||
|
ui->chbIsNull->setCheckState(Qt::CheckState::Checked); |
||||
|
} |
||||
|
ui->chbIsNull->show(); |
||||
|
|
||||
|
if(_lastFieldElement.attribute("isforeignkey") == "true") |
||||
|
{ |
||||
|
ui->chbIsForignKey->show(); |
||||
|
ui->cmbTablsName->show(); |
||||
|
ui->chbIsForignKey->setCheckState(Qt::CheckState::Checked); |
||||
|
ui->cmbTablsName->setCurrentText(_lastFieldElement.attribute("lookuptable")); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
ui->chbIsForignKey->setCheckState(Qt::CheckState::Unchecked); |
||||
|
} |
||||
|
ui->Append_btn->show(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
int a = index.row(); |
||||
|
int b = index.column(); |
||||
|
auto parent = index.parent(); |
||||
|
auto par0 = parent.parent(); |
||||
|
auto ac = index.data(); |
||||
|
qDebug()<<parent.data() << " " << par0.data(); |
||||
|
} |
||||
|
|
||||
|
MainWindow::eElementType MainWindow::getElementType(QModelIndex indInput) |
||||
|
{ |
||||
|
auto dataSptd = indInput.data().toString().split(" : "); |
||||
|
|
||||
|
if(dataSptd.at(0) == "root") |
||||
|
return MainWindow::eElementType::root; |
||||
|
else if(dataSptd.at(0) == "DB") |
||||
|
return MainWindow::eElementType::database; |
||||
|
else if(dataSptd.at(0) == "TBL") |
||||
|
return MainWindow::eElementType::table; |
||||
|
else if(dataSptd.at(0) == "FLD") |
||||
|
return MainWindow::eElementType::field; |
||||
|
else |
||||
|
return MainWindow::eElementType::unknown; |
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_cmbType_currentTextChanged(const QString &arg1) |
||||
|
{ |
||||
|
if(arg1 == "VARCHAR") |
||||
|
{ |
||||
|
ui->lineEdit_2->show(); |
||||
|
ui->label_2->setText("Len :"); |
||||
|
ui->label_2->show(); |
||||
|
ui->lineEdit_2->setText("200"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
ui->lineEdit_2->hide(); |
||||
|
ui->label_2->setText("Len :"); |
||||
|
ui->label_2->hide(); |
||||
|
ui->lineEdit_2->setText("200"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_actionsave_triggered() |
||||
|
{ |
||||
|
writeFile(); |
||||
|
} |
||||
|
|
||||
|
void MainWindow::on_actionEdit_Database_triggered() |
||||
|
{ |
||||
|
_fileName = QFileDialog::getOpenFileName(this, |
||||
|
tr("Open XML file"), "/home/", |
||||
|
tr("Address XML (*.xml);;All Files (*)")); |
||||
|
readFile(); |
||||
|
} |
@ -0,0 +1,87 @@ |
|||||
|
#ifndef MAINWINDOW_H |
||||
|
#define MAINWINDOW_H |
||||
|
|
||||
|
#include <QMainWindow> |
||||
|
#include <QtCore> |
||||
|
#include <QtGui> |
||||
|
#include <QtXml> |
||||
|
#include <QDebug> |
||||
|
|
||||
|
QT_BEGIN_NAMESPACE |
||||
|
namespace Ui { class MainWindow; } |
||||
|
QT_END_NAMESPACE |
||||
|
|
||||
|
class MainWindow : public QMainWindow |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
enum eStateLevel: quint8 |
||||
|
{ |
||||
|
createRoot, |
||||
|
createDatabase, |
||||
|
createTable, |
||||
|
createField, |
||||
|
editDatabase, |
||||
|
editTable, |
||||
|
editField |
||||
|
}; |
||||
|
enum eElementType:quint8 |
||||
|
{ |
||||
|
root, |
||||
|
database, |
||||
|
table, |
||||
|
field, |
||||
|
unknown |
||||
|
}; |
||||
|
|
||||
|
public: |
||||
|
MainWindow(QWidget *parent = nullptr); |
||||
|
~MainWindow(); |
||||
|
|
||||
|
private slots: |
||||
|
void on_actionCreate_Database_triggered(); |
||||
|
|
||||
|
void on_Append_btn_clicked(); |
||||
|
|
||||
|
void on_actionAdd_Table_triggered(); |
||||
|
|
||||
|
void on_actionAdd_Field_triggered(); |
||||
|
|
||||
|
void on_chbIsForignKey_stateChanged(int arg1); |
||||
|
|
||||
|
void on_cmbTablsName_currentIndexChanged(int index); |
||||
|
|
||||
|
void on_treeView_doubleClicked(const QModelIndex &index); |
||||
|
|
||||
|
void on_cmbType_currentTextChanged(const QString &arg1); |
||||
|
|
||||
|
void on_actionsave_triggered(); |
||||
|
|
||||
|
void on_actionEdit_Database_triggered(); |
||||
|
|
||||
|
private: |
||||
|
Ui::MainWindow *ui; |
||||
|
QStandardItemModel *_model; |
||||
|
QString _fileName; |
||||
|
|
||||
|
int _state = 0; |
||||
|
|
||||
|
QDomDocument _xmlDoc; |
||||
|
QString _xmlAddress; |
||||
|
QDomElement _root; |
||||
|
QVector<QString> _DBNameVector; |
||||
|
QVector<QDomElement> _DBElementVector; |
||||
|
QDomElement _lastDBElement; |
||||
|
QDomElement _lastTableElement; |
||||
|
QDomElement _lastFieldElement; |
||||
|
QDomElement* _lastDBPointer; |
||||
|
|
||||
|
void readFile(); |
||||
|
void readFile(QDomDocument xmlInput); |
||||
|
void writeFile(); |
||||
|
void hideWidgets(); |
||||
|
|
||||
|
eElementType getElementType(QModelIndex indInput); |
||||
|
|
||||
|
|
||||
|
}; |
||||
|
#endif // MAINWINDOW_H
|
@ -0,0 +1,304 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<ui version="4.0"> |
||||
|
<class>MainWindow</class> |
||||
|
<widget class="QMainWindow" name="MainWindow"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>0</x> |
||||
|
<y>0</y> |
||||
|
<width>800</width> |
||||
|
<height>600</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="windowTitle"> |
||||
|
<string>MainWindow</string> |
||||
|
</property> |
||||
|
<widget class="QWidget" name="centralwidget"> |
||||
|
<widget class="QTreeView" name="treeView"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>0</x> |
||||
|
<y>180</y> |
||||
|
<width>791</width> |
||||
|
<height>331</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="sizePolicy"> |
||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
||||
|
<horstretch>1</horstretch> |
||||
|
<verstretch>1</verstretch> |
||||
|
</sizepolicy> |
||||
|
</property> |
||||
|
<property name="sizeAdjustPolicy"> |
||||
|
<enum>QAbstractScrollArea::AdjustToContents</enum> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QPushButton" name="Append_btn"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>600</x> |
||||
|
<y>150</y> |
||||
|
<width>89</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Append</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLabel" name="label_1"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>10</x> |
||||
|
<y>10</y> |
||||
|
<width>181</width> |
||||
|
<height>17</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>TextLabel</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLineEdit" name="lineEdit_1"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>203</x> |
||||
|
<y>10</y> |
||||
|
<width>84</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLabel" name="label_2"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>510</x> |
||||
|
<y>10</y> |
||||
|
<width>67</width> |
||||
|
<height>17</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>TextLabel</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLineEdit" name="lineEdit_2"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>600</x> |
||||
|
<y>10</y> |
||||
|
<width>136</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QCheckBox" name="chbIsNull"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>291</x> |
||||
|
<y>10</y> |
||||
|
<width>95</width> |
||||
|
<height>23</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Allow Null</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QComboBox" name="cmbType"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>390</x> |
||||
|
<y>10</y> |
||||
|
<width>100</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<item> |
||||
|
<property name="text"> |
||||
|
<string/> |
||||
|
</property> |
||||
|
</item> |
||||
|
<item> |
||||
|
<property name="text"> |
||||
|
<string>INT</string> |
||||
|
</property> |
||||
|
</item> |
||||
|
<item> |
||||
|
<property name="text"> |
||||
|
<string>BOOLEAN</string> |
||||
|
</property> |
||||
|
</item> |
||||
|
<item> |
||||
|
<property name="text"> |
||||
|
<string>DOUBLE</string> |
||||
|
</property> |
||||
|
</item> |
||||
|
<item> |
||||
|
<property name="text"> |
||||
|
<string>VARCHAR</string> |
||||
|
</property> |
||||
|
</item> |
||||
|
</widget> |
||||
|
<widget class="QCheckBox" name="chbIsForignKey"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>10</x> |
||||
|
<y>70</y> |
||||
|
<width>101</width> |
||||
|
<height>23</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>IsForignKey</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QComboBox" name="cmbTablsName"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>150</x> |
||||
|
<y>70</y> |
||||
|
<width>131</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QSplitter" name="splitter"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>70</x> |
||||
|
<y>150</y> |
||||
|
<width>418</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="orientation"> |
||||
|
<enum>Qt::Horizontal</enum> |
||||
|
</property> |
||||
|
<widget class="QLabel" name="label_3"> |
||||
|
<property name="text"> |
||||
|
<string>TextLabel</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLineEdit" name="lineEdit_3"/> |
||||
|
<widget class="QLabel" name="label_4"> |
||||
|
<property name="text"> |
||||
|
<string>TextLabel</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
<widget class="QLineEdit" name="lineEdit_4"/> |
||||
|
</widget> |
||||
|
<widget class="QPushButton" name="cancel_btn"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>700</x> |
||||
|
<y>150</y> |
||||
|
<width>89</width> |
||||
|
<height>25</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Cancel</string> |
||||
|
</property> |
||||
|
</widget> |
||||
|
</widget> |
||||
|
<widget class="QMenuBar" name="menubar"> |
||||
|
<property name="geometry"> |
||||
|
<rect> |
||||
|
<x>0</x> |
||||
|
<y>0</y> |
||||
|
<width>800</width> |
||||
|
<height>22</height> |
||||
|
</rect> |
||||
|
</property> |
||||
|
<widget class="QMenu" name="menuFile"> |
||||
|
<property name="title"> |
||||
|
<string>File</string> |
||||
|
</property> |
||||
|
<addaction name="actionCreate_Database"/> |
||||
|
<addaction name="actionEdit_Database"/> |
||||
|
<addaction name="actionsave"/> |
||||
|
<addaction name="actionclese"/> |
||||
|
</widget> |
||||
|
<addaction name="menuFile"/> |
||||
|
</widget> |
||||
|
<widget class="QStatusBar" name="statusbar"/> |
||||
|
<widget class="QToolBar" name="toolBar"> |
||||
|
<property name="windowTitle"> |
||||
|
<string>toolBar</string> |
||||
|
</property> |
||||
|
<attribute name="toolBarArea"> |
||||
|
<enum>TopToolBarArea</enum> |
||||
|
</attribute> |
||||
|
<attribute name="toolBarBreak"> |
||||
|
<bool>false</bool> |
||||
|
</attribute> |
||||
|
<addaction name="actionCreate_Database"/> |
||||
|
<addaction name="actionEdit_Database"/> |
||||
|
<addaction name="actionAdd_Table"/> |
||||
|
<addaction name="actionAdd_Field"/> |
||||
|
</widget> |
||||
|
<action name="actionCreate_Database"> |
||||
|
<property name="icon"> |
||||
|
<iconset resource="res/Icons.qrc"> |
||||
|
<normaloff>:/Icons/new.png</normaloff>:/Icons/new.png</iconset> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Create Database</string> |
||||
|
</property> |
||||
|
<property name="shortcut"> |
||||
|
<string>Ctrl+D</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
<action name="actionEdit_Database"> |
||||
|
<property name="icon"> |
||||
|
<iconset resource="res/Icons.qrc"> |
||||
|
<normaloff>:/Icons/edit.png</normaloff>:/Icons/edit.png</iconset> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Edit Database</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
<action name="actionclese"> |
||||
|
<property name="text"> |
||||
|
<string>close</string> |
||||
|
</property> |
||||
|
<property name="toolTip"> |
||||
|
<string>close</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
<action name="actionAdd_Table"> |
||||
|
<property name="icon"> |
||||
|
<iconset resource="res/Icons.qrc"> |
||||
|
<normaloff>:/Icons/add.png</normaloff>:/Icons/add.png</iconset> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Add Table</string> |
||||
|
</property> |
||||
|
<property name="shortcut"> |
||||
|
<string>Ctrl+T</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
<action name="actionAdd_Field"> |
||||
|
<property name="icon"> |
||||
|
<iconset resource="res/Icons.qrc"> |
||||
|
<normaloff>:/Icons/column.png</normaloff>:/Icons/column.png</iconset> |
||||
|
</property> |
||||
|
<property name="text"> |
||||
|
<string>Add Field</string> |
||||
|
</property> |
||||
|
<property name="shortcut"> |
||||
|
<string>Ctrl+F</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
<action name="actionsave"> |
||||
|
<property name="text"> |
||||
|
<string>save</string> |
||||
|
</property> |
||||
|
</action> |
||||
|
</widget> |
||||
|
<resources> |
||||
|
<include location="res/Icons.qrc"/> |
||||
|
</resources> |
||||
|
<connections/> |
||||
|
</ui> |
@ -0,0 +1,8 @@ |
|||||
|
<RCC> |
||||
|
<qresource prefix="/Icons"> |
||||
|
<file>new.png</file> |
||||
|
<file>edit.png</file> |
||||
|
<file>column.png</file> |
||||
|
<file>add.png</file> |
||||
|
</qresource> |
||||
|
</RCC> |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 28 KiB |
@ -0,0 +1,13 @@ |
|||||
|
#ifndef STATE_H |
||||
|
#define STATE_H |
||||
|
|
||||
|
#include <QtCore> |
||||
|
|
||||
|
//class EnumsLebel :public QObject
|
||||
|
//{
|
||||
|
//public:
|
||||
|
|
||||
|
// Q_ENUM(eStateLevel)
|
||||
|
|
||||
|
//};
|
||||
|
#endif // STATE_H
|
Loading…
Reference in new issue