Rev 196 |
Rev 201 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
model_is_build = false;
// MainWindow::readModel();
//QString model_str;
/*
MainWindow::creatModelString();
int i;
i++;
QFile file_tmp("./temp.txt");
bool ok;
ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream out(&file_tmp);
out << MainWindow::modelString;
file_tmp.close();
*/
ui->treeWidget->setAlternatingRowColors(true);
ui->treeWidget_2->setAlternatingRowColors(true);
ui->treeWidget->setIconSize(QSize(30,30));
ui->treeWidget_2->setIconSize(QSize(128,128));
MainWindow::readSettings();
MainWindow::openDataBase();
classesIcons = MainWindow::getClassesIcons(); // ïîëó÷èì èêîíêè äëÿ êëàññîâ
MainWindow::initComboBox();
// MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("11"));
MainWindow::initListModelsTablle();
MainWindow::readModels();
// MainWindow::creatModelString();
//int i;
//i++;
/*
QFile file_tmp("./modelstring.txt");
bool ok;
file_tmp.remove();
ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream out(&file_tmp);
out.setCodec("cp1251");
out << MainWindow::modelString;
file_tmp.close();
*/
ui->treeWidget_2->hideColumn(1);
ui->treeWidget_2->hideColumn(2);
ui->treeWidget_2->hideColumn(3);
ui->treeWidget_2->hideColumn(4);
getDatabaseData();
//// sql_mogel = new QSqlTableModel();
sql_mogel = new MyModel();
model_is_build = true;
connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex)));
connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex)));
ui->pushButton_3->setEnabled(false);
ui->pushButton_4->setEnabled(false);
// setFrm.show();
connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // âûáîð â ãëàâíîé ôîðìå â ìåíþ "Áàçà äàííûõ" ïóíêòà "Ïàðàìåòðû ñîåäèíåíèÿ"
connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting()));
// connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex)));
picture_delegate = new CPictureDelegate(this);
iconDelegate = new IconDelegate(this);
// fileForm.show();
}
MainWindow::~MainWindow()
{
delete sql_mogel;
delete ui;
delete model_for_ListModelsTable;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
bool MainWindow::readModel(){
bool result;
QString model_str;
QFile file("modelstring.txt");
// QFile file("model.txt");
rootItem1 = new QTreeWidgetItem(ui->treeWidget);
rootItem1->setText(0, tr("Óðîâåíü 1"));
// rootItem2 = new QTreeWidgetItem(rootItem1);
// rootItem2->setText(0, tr("óðîâåíü 2"));
rootItem1->setCheckState(0,Qt::Checked);
// rootItem2->setCheckState(0,Qt::Checked);
result = file.open(QIODevice::ReadOnly);
if (result) {
model_str = QString(tr(file.readAll()));
}
setupModelData(model_str.split(QString("\n")), rootItem1, -1);
return result;
}
void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row)
{
QList<QTreeWidgetItem*> parents;
QList<int> indentations;
parents << parent;
indentations << 0;
int number = 0;
while (number < lines.count()) {
int position = 0;
while (position < lines[number].length()) {
if (lines[number].mid(position, 1) != " ")
break;
position++;
}
QString lineData = lines[number].mid(position).trimmed();
if (!lineData.isEmpty()) {
// Read the column data from the rest of the line.
QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts);
QList<QVariant> columnData;
for (int column = 0; column < columnStrings.count(); ++column)
columnData << columnStrings[column];
if (position > indentations.last()) {
// The last child of the current parent is now the new parent
// unless the current parent has no children.
if (parents.last()->childCount() > 0) {
parents << parents.last()->child(parents.last()->childCount()-1);
indentations << position;
}
} else {
while (position < indentations.last() && parents.count() > 0) {
parents.pop_back();
indentations.pop_back();
}
}
// Append a new item to the current parent's list of children.
// // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last()));
QTreeWidgetItem* itm_tmp;
itm_tmp = new QTreeWidgetItem( parents.last());
itm_tmp->setText(0, QString(columnData.at(0).toString()));
if (columnData.at(1).toString() == "true") {
itm_tmp->setCheckState(0,Qt::Checked);
}
else itm_tmp->setCheckState(0,Qt::Unchecked);
if (columnData.count()>2)
{
QString class_id;
QPixmap pxmp;
QIcon icon;
class_id = QString(columnData.at(2).toString());
pxmp = MainWindow::classesIcons.value(class_id);
// itm_tmp->setText(1, QString(columnData.at(2).toString())); // id êëàññà
itm_tmp->setText(1, class_id); // id êëàññà
itm_tmp->setText(2, QVariant(number).toString()); // íîìåð ñòðîêè â ôàéëå-ìîäåëè îòîáðàæåíèÿ
itm_tmp->setText(3, QVariant(indentations.size()).toString()); // óðîâåíü âëîæåíèÿ
itm_tmp->setText(4, QVariant(row).toString()); // íîìåð ñòðîêè â ôàéëå
if (!pxmp.isNull())
{
icon.addPixmap(pxmp);
itm_tmp->setIcon(0, icon);
}
}
}
number++;
}
}
/*
void MainWindow::openBase()
{
db = QSqlDatabase::addDatabase("QMYSQL");
pdb = &db;
raportFrm.pdb = &db;
pdb->setHostName(hostName);
pdb->setDatabaseName(baseName);
pdb->setUserName(userName);
pdb->setPassword(password);
bool ok = pdb->open();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
pdb->lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
if (ok)
{lineEdit-> insert(tr("Áàçà óñïåøíî îòêðûòà"));
}
else {lineEdit-> insert(tr("Áàçà íåäîñòóïíà. Êîä îøèáêè: "));
lineEdit-> insert(pdb->lastError().text());
}
model = new QSqlTableModel(this);
model->setTable(tableName);
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->setSort(0, Qt::AscendingOrder);
model->select();
QSqlField field(tr("age"), QVariant::Int);
field.setValue(QString(tr("123")));
bool okey;
int index;
QSqlRecord record;
tableView->setModel(model);
view.setModel(model);
tableView->setAlternatingRowColors(true);
view.setAlternatingRowColors(true);
tableView->resizeColumnsToContents();
view.resizeColumnsToContents();
tableView->show();
initTreeWidget();
}
*/
QString MainWindow::creatModelString(QTreeWidgetItem* model){
MainWindow::modelString.clear(); // î÷èùàåì ñòðîêó ìîäåëè
// for (int i =0; i < rootItem1->childCount(); ++i )
{MainWindow::addChildsString(model, 0);}
return MainWindow::modelString;
// {MainWindow::addChildsString(ui->treeWidget, 0);}
/*
int root_item_child_count;
int i;
root_item_child_count = rootItem1->childCount();
i++;
*/
}
void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){
int child_count;
child_count = parentItem->childCount();
for (int i=0; i < child_count; ++i){
for (int m=0; m < level; ++m){
modelString.append(tr(" ")); // ÷åòûðå ïðîáåëà - ïðèçíàê òîãî, ÷òî ýòî íîâûé óðîâåíü âëîæåíèÿ
}
modelString.append(parentItem->child(i)->text(0)); // â ïåðâîé êîëîíêå - èìÿ êëàññà
modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà
if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // åñëè ãàëî÷êà ñòîèò, çàíîñèì "true", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ áóäóò
else {modelString.append(tr("false"));} // åñëè êëàññ íå âûáðàí - çàíîñèì "false", ýëåìåíòû êëàññà â ïðåäñòàâëåíèè îòîáðàæàòüñÿ íå áóäóò
modelString.append(tr("\t\t\t\t")); // ÷åòûðå òàáóëÿöèè - ïðèçíàê íîâîãî ñòîëáöà
modelString.append(parentItem->child(i)->text(1)); // âî âòîðîé êîëîíêå - ID êëàññà
modelString.append(tr("\n")); // êîíåö ñòðîêè
if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);}
}
int i;
i++;
}
bool MainWindow::openDataBase(){
QString errorString;
sql = QSqlDatabase::addDatabase("QMYSQL");
// sql.setDatabaseName(tr("an_db"));
// // // sql.setDatabaseName(tr("inventory"));
sql.setDatabaseName(baseName);
// // // sql.setHostName(tr("localhost"));
sql.setHostName(hostName);
// // // sql.setUserName(tr("an"));
sql.setUserName(userName);
// // // sql.setPassword(tr("393939"));
sql.setPassword(password);
bool ok;
ok = sql.open();
/*
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lastError().text() ); // Òåêñò ñîîáùåíèÿ.
}
*/
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
else {
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Connect"), // Çàãîëîâîê.
QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ.
}
return ok;
}
bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){
QSqlQuery q;
QString sql_str;
QString field_name_str;
QString root_class_name;
//bool ok;
//int field_name;
//ui->treeWidget->clear();
root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà
rootItem1 = new QTreeWidgetItem(ui->treeWidget);
root_items_list << rootItem1;
rootItem1->setText(0, modelName);
rootItem1->setCheckState(0,Qt::Checked);
rootItems.append(rootItem1);
rootItem2 = new QTreeWidgetItem(rootItem1);
rootItem2->setText(0, root_class_name);
rootItem2->setText(1, rootClassID);
rootItem2->setCheckState(0,Qt::Checked);
addChildsItems(rootItem2, -1);
/*
sql_str = tr("select * "
" from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
sql_str.append(rootClassID);
sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
field_name = q.record().indexOf(tr("FieldName"));
while(q.next()){
field_name_str = q.value(field_name).toString();
}
*/
}
bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){
QSqlQuery q;
QString sql_str;
QString field_name_str;
QString root_class_name;
//bool ok;
//int field_name;
//ui->treeWidget->clear();
root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà
// rootItem1 = new QTreeWidgetItem(ui->treeWidget);
// root_items_list << rootItem1;
// rootItem1->setText(0, modelName);
// rootItem1->setCheckState(0,Qt::Checked);
// rootItems.append(rootItem1);
// root_item->removeChild(root_item->child(0)); // î÷èùàåì ñïèñîê äî÷åðíèõ êëàññîâ
if (root_item->childCount()==0){ // íåò êîðíåâîãî êëàññà, ñîçäàäèì åãî
QTreeWidgetItem* item_tmp;
item_tmp = new QTreeWidgetItem (root_item);
item_tmp->setText(4, QVariant(row).toString());
}
if (root_item->childCount()==1){ // êîðíåâîé êëàññ åñòü è îí ïóñòîé, î÷èùàòü åãî íå íàäî
root_item->child(0)->setText(0, root_class_name);
root_item->child(0)->setText(1, rootClassID);
root_item->child(0)->setCheckState(0,Qt::Checked);
root_item->setText(4, QVariant(row).toString());
}
//delete rootItem2;
// rootItem2 = new QTreeWidgetItem(rootItem1);
// rootItem2->setText(0, root_class_name);
// rootItem2->setText(1, rootClassID);
// rootItem2->setCheckState(0,Qt::Checked);
int child_count = root_item->child(0)->childCount();
for (int i=0; i < child_count; i++){ // åñëè êîðíåâîé êëàññ åñòü è íå ïóñòîé, î÷èùàåì åãî
root_item->child(0)->removeChild(root_item->child(0)->child(0));
}
child_count = root_item->child(0)->childCount();
addChildsItems(root_item->child(0), row);
/*
sql_str = tr("select * "
" from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
sql_str.append(rootClassID);
sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
field_name = q.record().indexOf(tr("FieldName"));
while(q.next()){
field_name_str = q.value(field_name).toString();
}
*/
}
QString MainWindow::ClassName(QString class_id){ //âîçâðàùàåò èìÿ êëàññà ïî åãî ID
QSqlQuery q;
QString sql_str;
QString class_name_str;
bool ok;
int field_class_name;
sql_str = tr("select * "
" from ListOfClasses where ListOfClasses.ID = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
sql_str.append(class_id);
sql_str.append(tr("' "));
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
field_class_name = q.record().indexOf(tr("ClassName"));
while(q.next()){
class_name_str = q.value(field_class_name).toString();
}
return class_name_str;
}
void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // äîáîâëÿåì ê ýëåìåíòó äåðåâà â êà÷åñòâå äî÷åðíèõ ýëåìåíòîâ âñå êëàññû, äëÿ êîòîðûõ êëàññ ýëåìåíòà ÿâëÿåòñÿ êîíòåéíåðîì
QStringList chields_list;
QString parent_ID;
QTreeWidgetItem *Item_tmp;
parent_ID = perent_class_item->text(1);
int chields_count, i;
chields_list = MainWindow::classChields(parent_ID);
if(chields_list.isEmpty()) return;
chields_count = chields_list.size();
for (int l = 0; l < chields_count; ++l){
QString chield_class_name, chield_id;
chield_id = chields_list.at(l);
chield_class_name = MainWindow::ClassName(chield_id);
Item_tmp = new QTreeWidgetItem(perent_class_item);
Item_tmp->setText(0, chield_class_name);
Item_tmp->setText(1, chield_id);
Item_tmp->setCheckState(0, Qt::Checked);
Item_tmp->setText(4, QVariant(row).toString());
MainWindow::addChildsItems(Item_tmp, row);
}
i++;
}
/********************************************************
* Ôóíêöèÿ âîçâðàùàåò ñïèñîê "äî÷åðíèõ" êëàññîâ
*
*
*
********************************************************/
QStringList MainWindow::classChields(QString class_id){
// QMap<QString, QString> map;
// TClass class_tmp;
// QList <TClass> chields_class_list; // ñïèñîê äî÷åðíèõ êëàññîâ
QStringList result;
QSqlQuery q;
QString sql_str;
QString classIdentifer_str; // â ýòîì ïîëå ëåæèò èäåíòèôèêàòîð êëàññà-êîíòåéíåðà
QString field_id_str;
bool ok;
int field_classIdentifer;
sql_str = tr("select * "
" from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
sql_str.append(class_id);
sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' "));
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
}
field_classIdentifer = q.record().indexOf(tr("ClassIdentifer"));
while(q.next()){
classIdentifer_str = q.value(field_classIdentifer).toString();
result.append(classIdentifer_str);
}
return result;
}
QMap <QString, QString> MainWindow::getClassList(){ // ïîëó÷àåì ñïèñîê êëàññîâ
QMap <QString, QString> result_map;
QSqlQuery q;
QString sql_str;
QString class_name_str, class_id_str;
int field_class_id, field_class_name;
bool ok;
sql_str = tr("select * "
" from ListOfClasses " //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return result_map; // åñëè îøèáêà - âîçâðàùàåì ïóñòîé ñïèñîê
}
field_class_id = q.record().indexOf(tr("ID"));
field_class_name = q.record().indexOf(tr("ClassName"));
while(q.next()){
class_name_str = q.value(field_class_name).toString();
class_id_str = q.value(field_class_id).toString();
result_map[class_id_str] = class_name_str;
}
return result_map;
}
void MainWindow::initComboBox(){
QStringList classesNameList;
QStringList classesID_list;
QStringList tmp_stringList;
QString tmp_str;
class_list_map = MainWindow::getClassList();
classesID_list = class_list_map.keys();
classesNameList = class_list_map.values();
QMapIterator<QString, QString> interator(class_list_map);
// ui->comboBox->addItems(classesID_list);
// ui->comboBox->addItems(classesNameList);
while (interator.hasNext()) {
interator.next();
tmp_str = interator.value();
tmp_str.append(tr(" \t(ID="));
tmp_str.append(interator.key());
tmp_str.append(tr(")"));
tmp_stringList << tmp_str;
}
// int count = ui->comboBox->count();
ui->comboBox->clear();
ui->comboBox->addItems(tmp_stringList);
}
void MainWindow::on_comboBox_currentIndexChanged( int index ){
QStringList classesNameList;
QStringList classesID_list;
QString ID_str;
if (index == -1) return;
if (!comboBox_slot_enable) return; // èíäåêñ ïîìåíÿëà ïðîãðàììà, îí íå áûë èçìåíåí âðó÷íóþ, âûõîäèì
int row;
classesID_list = class_list_map.keys();
classesNameList = class_list_map.values();
ID_str = classesID_list[index];
ui->label->setText(ID_str);
if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1)
{
row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt();
model_is_build = false; // ÷òîáû íå âûçûâàëîñü ñîáûòèå on_treeWidget_itemChanged
rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row);
model_is_build = true; // òåïåðü ïóñòü âûçûâàåòñÿ
QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); //
model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str));
}
getDatabaseData();
}
void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){
int i;
i++;
QTreeWidgetItem * item_tmp;
QString mdl_str;
QString row; // íîìåð ñòðîêè â òàáëèöå ìîäåëåé, ñîîòâåòñòâóþùèé èçìåíåííîé ìîäåëå
QList <QTreeWidgetItem *> mdl_itm_list;
QList <int> rows_list;
if ((column) == 0 && (model_is_build)) {
// if (!model_is_build) return; // ìîäåëü åù¸ íå ïîñòðîåíà
mdl_itm_list = models_items.values();
rows_list = models_items.keys();
row= item->text(4);
if ( mdl_itm_list.indexOf(item) != -1){ // èçìåí¸í êîðíåâîé èòåì (ñàìà ìîäåëü)
if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1));
else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0));
}
if (!row.isEmpty()){
int row_int;
row_int = QVariant(row).toInt();
if (rows_list.indexOf(row_int) != -1)
{
item_tmp = models_items[row_int];
mdl_str = MainWindow::creatModelString(item_tmp);
model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str));
}
}
}
/*
QTreeWidgetItem * item_tmp;
item_tmp = item;
while (item_tmp ){
item_tmp = item_tmp->parent();
}
*/
if ((column) == 0 && (model_is_build)) getDatabaseData();
}
void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){
int i;
i++;
if (root_items_list.indexOf(item) != -1) {
QStringList classesNameList;
QStringList classesID_list;
int index;
classesID_list = class_list_map.keys();
classesNameList = class_list_map.values();
if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // åñëè ìîäåëü íå ïóñòàÿ, óçíàåì êîðíåâîé êëàññ
else { // åñëè ïóñòàÿ
ui->comboBox->setEnabled(true);
return;
}
comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè
if (index != -1) ui->comboBox->setCurrentIndex(index);
comboBox_slot_enable = true;
ui->comboBox->setEnabled(true);
}
// if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true);
else ( ui->comboBox->setEnabled(false));
}
QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // ïîëó÷àåì ñïèñîê ïîëåé êëàññà
}
void MainWindow::initListModelsTablle(){
model_for_ListModelsTable = new QSqlTableModel();
model_for_ListModelsTable->setTable(tr("ListOfModels"));
// model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange);
model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit);
ui->tableView_2->setModel(model_for_ListModelsTable);
model_for_ListModelsTable->select();
ui->treeWidget->hideColumn(1);
ui->treeWidget->hideColumn(2);
ui->treeWidget->hideColumn(3);
ui->treeWidget->hideColumn(4);
ui->tableView_2->hideColumn(0);
ui->tableView_2->hideColumn(2);
ui->tableView_2->hideColumn(3);
ui->tableView_2->hideColumn(4);
ui->tableView_2->resizeColumnsToContents();
ui->tableView_2->setAlternatingRowColors(true);
ui->pushButton_7->setEnabled(false);
ui->pushButton_8->setEnabled(false);
}