Rev 256 |
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);
/*
QPalette p = this->palette();
p.setBrush(this->backgroundRole(), QBrush(QColor(255,255,255,128)));
this->setAutoFillBackground(true);
this->setPalette(p);
*/
ui->centralWidget->setLayout(ui->verticalLayout);
ui->tab->setLayout(ui->horizontalLayout);
ui->tab_2->setLayout(ui->horizontalLayout_3);
ui->tab_3->setLayout(ui->horizontalLayout_7);
ui->tab_4->setLayout(ui->horizontalLayout_8);
// 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->setColumnWidth(0, 400);
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();
initWmiTree();
// 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);
ui->treeWidget_2->hideColumn(5);
getDatabaseData();
//// sql_mogel = new QSqlTableModel();
sql_mogel = new MyModel();
/// filter_model = new MyModel();
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
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)));
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput()));
connect(&wmiProcess, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError()));
ui->pushButton_3->setEnabled(false);
ui->pushButton_4->setEnabled(false);
ui->pushButton_9->setEnabled(false);
ui->pushButton_10->setEnabled(false);
ui->pushButton_11->setEnabled(false);
ui->pushButton_12->setEnabled(false);
// setFrm.show();
// treeForm.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);
fileDelegate = new FileDelegate(this);
// fileForm.show();
doc = ui->textEdit->document();
cursor = new QTextCursor(doc);
// buildReport(true);
all_reading = false; // íåò ïðî÷èòàííûõ äàííûõ èç ïðîöåññà
// wmiThread = new WmiThread(this);
}
MainWindow::~MainWindow()
{
delete sql_mogel;
delete filter_model;
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, tr("1"));
return result;
}
void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id)
{
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->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
/*
QLineEdit * edit_line;
edit_line = new QLineEdit(this);
ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line);
*/
//static QStandartDelegate delegate;
ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate);
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;
QString filtr_str;
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(6, model_id); // id ìîäåëè
itm_tmp->setText(2, QVariant(number).toString()); // íîìåð ñòðîêè â ôàéëå-ìîäåëè îòîáðàæåíèÿ
itm_tmp->setText(3, QVariant(indentations.size()).toString()); // óðîâåíü âëîæåíèÿ
itm_tmp->setText(4, QVariant(row).toString()); // íîìåð ñòðîêè â ôàéëå
filtr_str = getFiltrString(model_id,class_id);
itm_tmp->setText(5,filtr_str);
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;
}
tmp_stringList << tr("íå çàäàíî");
// 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 (ui->comboBox->itemText(index) == tr("íå çàäàíî")) 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;
ui->pushButton_9->setEnabled(false);
ui->pushButton_10->setEnabled(false);
ui->pushButton_11->setEnabled(false);
ui->pushButton_12->setEnabled(false);
// ui->tableView->reset();
// MainWindow::filtr_model->clear();
disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
delete filter_model;
filter_model = new QSqlTableModel();
/// filter_model = new MyModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
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 { // åñëè ïóñòàÿ
index = classesID_list.count();
comboBox_slot_enable = false; // ÷òîáû ñëîò comboBox íå ìåíÿë ñòðîêó ìîäåëè
ui->comboBox->setCurrentIndex(index);
ui->comboBox->setEnabled(true);
comboBox_slot_enable = 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 // âûáðàííûé èòåì ñîäåðæèò íàçâàíèå êëàññà
{
QString class_id;
QString model_id;
QString filtr_str;
QString inctance;
QStringList conditionList;
class_id = item->text(1);
model_id = item->text(6);
inctance = MainWindow::getClassInctance(class_id);
filtr_str = tr("`Model_ID` = ");
filtr_str.append(model_id);
filtr_str.append(tr(" AND `Class_ID` = "));
filtr_str.append(class_id);
// filtr_str.append(tr("`"));
disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
delete filter_model;
/// filter_model = new MyModel();
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
filter_model->setTable(tr("Filters"));
filter_model->setFilter(filtr_str);
filter_model->select();
filter_model->sort(0,Qt::AscendingOrder);
ui->tableView_3->setModel(filter_model);
ui->tableView_3->hideColumn(0);
ui->tableView_3->hideColumn(1);
ui->tableView_3->hideColumn(2);
filterSpinDelegate.setClassID(class_id);
filterSpinDelegate.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate);
// ui->tableView_3->setItemDelegate();
conditionList <<"" << "and" << "or" << "(" << "and (" << "or (";
filterConditionDelegate.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate);
conditionList.clear();
conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL";
filterConditionDelegate_1.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1);
conditionList.clear();
conditionList <<"" << ")";
filterConditionDelegate_2.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2);
ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate);
ui->pushButton_9->setEnabled(true);
ui->pushButton_10->setEnabled(true);
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->treeWidget->hideColumn(5);
ui->treeWidget->hideColumn(6);
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);
}
void MainWindow::buildReport(bool advanced){
// QTreeWidgetItem * hitm;
// hitm = ui->treeWidget_2->headerItem();
// int count = root_items_list.count();
//int count = ui->treeWidget_2->rootIndex();
doc->clear();//î÷èùàåì äîêóìåíò
int list_count;
if (rootItems.isEmpty()) return;
list_count = rootItems.count();
for (int i=0; i < list_count; i++){
getReport(rootItems.at(i), advanced);
}
// (bool)QTextDocumentWriter("raport.odt").write(doc);
}
void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // ñîçäàåò îò÷åò äëÿ êîíêðåòíîé ìîäåëè
// QTextDocument doc;
// QTextCursor cursor(&doc);
QTextCharFormat char_fmt;
bool ok;
/**************
// char_fmt.setBackground(Qt::red);
cursor.insertText(tr("Ì1\n"),char_fmt);
QImage img;
ok = img.load("./hdd5.png");
doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img);
cursor.insertImage("myimage");
cursor.insertText(tr("Æåñòêèé äèñê\n"),char_fmt);
(bool)QTextDocumentWriter("test.odt").write(&doc);
***************/
QString model_name;
QString rootClassID;
QString rootClassInctance;
QFont font;
QBrush brush;
brush.setColor(Qt::darkRed);
char_fmt.setForeground(brush);
font.setBold(true);
char_fmt.setFont(font);
model_name = model_item->text(0);
if (model_item->checkState(0) == false) return; // ìîäåëü íå âûäåëåíà äëÿ îòîáðàæåíèÿ
newPage();
/*******************
QTextBlockFormat textFormat;
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
cursor->setBlockFormat(textFormat);
cursor->insertText(tr("Íîâàÿ ñòðàíèöà"));
cursor->insertBlock();
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
cursor->setBlockFormat(textFormat);
********************/
if (!(model_item->childCount() > 0)) return; // ìîäåëü ïóñòà (íå ñîäåðæèò êëàññîâ)
rootClassID = model_item->child(0)->text(1);
rootClassInctance = getClassInctance(rootClassID);
cursor->insertText(model_name, char_fmt);
cursor->insertText(tr("\n"));
if (model_item->child(0)->checkState(0)) // åñëè â ìîäåëè êîðíåâîé êëàññ âûáðàí äëÿ îòîáðàæåíèÿ (ñòîèò ãàëî÷êà), òî
{
///// QTreeWidgetItem * item_tmp;
///// item_tmp = new QTreeWidgetItem(item); // â äåðåâå, îòîáðàæàþùåì îáúåêòû êëàññîâ, ñîçäàåì íîâûé óçåë
///// item_tmp->setText(0, model_item->child(0)->text(0)); // ñ íàçâàíèåì êëàññà
//showClassObjects(item_tmp, model_item->child(0)); // è âûâîäèì âñå îáúåêòû äàííîãî êëàññà
///// showObjects(item_tmp, model_item->child(0), tr(""));
printChild(model_item->child(0), tr(""), advanced, 1);
}
}
void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){//â ðàïîðò äîáàâëÿåì äî÷åðíèå êëàññû
QString classID; // èäåíòèôèêàòîð êëàññà
QString parentClassID; // èäåíòèôèêàòîð ðîäèòåëüñêîãî êëàññà
QString pointerField; // èìÿ ïîëÿ-óêàçàòåëÿ íà ðîäèòåëüñêèé êëàññ
QString inctance; // èìÿ òàáëèöû, õðàíèëèùà
QString className; // èìÿ êëàññà
QString modelID; // èäåíòèôèêàòîð ìîäåëè
QString add_filtr; // äîïîëíèòåëüíûé ôèëüòð
int field_ID;
int icon_field_index;
bool filtr_empty;
bool ok;
QSqlQuery q;
QString sql_str;
QString str_tmp;
QTreeWidgetItem * title_item;
QIcon icon;
QMap<QString, QString> fieldsTypesList;//çäåñü â êà÷åñòâå êëþ÷å áóäåì õðàíèòü èìåíà ïîëåé, çíà÷åíèÿìè áóäóò èõ òèïû
//QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà
// // // font.setBold(true);
filtr_empty = filtr.isEmpty();
classID = model_item->text(1);
modelID = model_item->text(6);
add_filtr = MainWindow::getFiltrString(modelID, classID);
icon = model_item->icon(0);
parentClassID = model_item->parent()->text(1);
pointerField = getPointerFieldName(parentClassID, classID);
className = model_item->text(0);
inctance = getClassInctance(classID);
if (!model_item->checkState(0)) return;
QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly;
QTextTableFormat tableFormat;
// QPen pen;
QBrush brush;
QFont font;
// pen.setColor(Qt::red);
// charFormatItalic.setTextOutline(pen);
//QFont font;
brush.setColor(Qt::blue);
font.setItalic(true);
charFormatItalicOnly.setFont(font);
//charFormatItalic.setFontItalic(true);
font.setBold(true);/////////////////
charFormatItalic.setFont(font);
charFormatItalic.setForeground(brush);
charFormatItalicBold.setFont(font);
charFormatItalicBold.setForeground(brush);
//charFormatItalic.setFontWeight(16);
pos++;
for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
cursor->insertText(className, charFormatItalic);
cursor->setCharFormat(charFormatBase);
cursor->insertText(tr("\n"));
sql_str = tr("select * "
" from " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà
);
sql_str.append(inctance);
if (filtr.isEmpty() && (!add_filtr.isEmpty())) // ôèëüòð ïóñòîé, äîïîëíèòåëüíûé ôèëüòð íå ïóñòîé
{
filtr.append(tr ("where "));
filtr.append(add_filtr);
}
if (!filtr.isEmpty()) { // åñëè ôèëüòð íå ïóñòîé
sql_str.append(tr(" "));
sql_str.append(filtr); // äîáàâëÿåì â çàïðîñ ôèëüòð
}
q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QString debug_str;
debug_str.append(tr("ôóí showObjects(): Database Error "));
debug_str.append(tr(" õð: "));
debug_str.append(inctance);
debug_str.append(tr(" ô: "));
debug_str.append(filtr);
debug_str.append(q.lastError().text());
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê.
debug_str
// q.lastError().text()
); // Òåêñò ñîîáùåíèÿ.
return;
}
field_ID = q.record().indexOf(tr("ID"));
icon_field_index = q.record().indexOf(tr("Icon"));
int k=0;
QStringList fieldsNamesList;// ñïèñîê èì¸í ïîëåé òàáëèöû
QList<TField> FieldsList; //ñïèñîê ïîëåé êëàññà
QMap<QString, TField> fieldsMap;// çäåñü áóäåì â êà÷åñòâå êëþ÷åé õðàíèòü èìåíà ïîëåé, à â êà÷åñòâå çíà÷åíèé - íåïîñðåäñòâåííî ñîîòâåòñòâóþùèå ïîëÿ
QMap <QString, QString> fieldsValues;// çäåñü áóäåì õðàíèòü çíà÷åíèÿ ïîëåé, êëþ÷àìè áóäóò ñëóæèòü èìåíà ïîëåé
FieldsList = getFieldList(classID); // ïîëó÷àåì ñïèñîê ïîëåé
if(FieldsList.count()>0){
for(int i=0; i < FieldsList.count(); i++){ //ñîñòàâèì ïàðû (èìÿ ïîëÿ-òèï ïîëÿ)
fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType);
fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i));
}
// fieldsNamesList = fieldsTypesList.keys(); // ïîëó÷èì ñïèñîê èìåí ïîëåé
}
// icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
while(!q.record().fieldName(k).isEmpty()){// ïîêà íå ïåðåáåð¸ì âñå ïîëÿ
fieldsNamesList.append(q.record().fieldName(k++));
}
//icon_field_index = fieldsNamesList.indexOf(tr("Icon"));//îïðåäåëèì èíäåêñ ïîëÿ ñ èêîíêîé
while(q.next()){
if (q.record().count() > 1)
{
QString value_tmp;
QString ID_tmp;
QString space;
// // // // QTreeWidgetItem * itm;
ID_tmp = q.value(field_ID).toString(); // îïðåäåëÿåì èäåíòèôèêàòîð îáúåêòà
value_tmp = q.value(1).toString(); // îïðåäåëÿåì èìÿ îáúåêòà (äîëæíî õðàíèòüñÿ â ïåðâîì ïîëå)
// itm = new QTreeWidgetItem(parent_object_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
/***************************
itm = new QTreeWidgetItem(title_item); // äîáàâëÿåì â äåðåâî óçåë, ñîîòâåòñòâóþùèé îáúåêòó
itm->setText(0, value_tmp);
itm->setText(1, tr("object"));
itm->setText(2, ID_tmp);
******************************/
if (icon_field_index != -1){ // åñëè èìååòñÿ ïîëå ñ èêîíêàìè
QVariant data;
QByteArray bytes;
QPixmap pix;
QIcon icn;
QMap <QString, QPixmap> pixmap_map;
QList <QString> id_list;
QList <QPixmap> pixmap_list;
pixmap_map = MainWindow::getObjectsIcon(inctance);
if (!pixmap_map.isEmpty()) {
id_list = pixmap_map.keys();
pixmap_list = pixmap_map.values();
}
if (id_list.indexOf(ID_tmp) != -1) {
pix = pixmap_list.at(id_list.indexOf(ID_tmp));
}
// data = q.record().value(icon_field_index);
// bytes = q.record().value(icon_field_index).toByteArray();
// if (data.isValid() && (!data.isNull())) {
// if (!bytes.isEmpty()){
// pix.loadFromData(data.toByteArray());
// pix.loadFromData(bytes);
if(!pix.isNull()) {
if (pix.height() > 128) pix = pix.scaledToHeight(128);
QString fname = value_tmp;
fname.append(tr(".png"));
pix.toImage().save(fname);
doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage());
// for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
cursor->insertImage(fname);
// cursor->insertText(tr("\n"));
}
else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
// // // icn.addPixmap(pix);
// // // itm->setIcon(0, icn);
// }
}
else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
cursor->insertText( value_tmp);
cursor->insertText( tr("\n"));
// q.first();
if(advanced && (fieldsNamesList.count()>0)){ // åñëè îò÷åò ðàñøèðåííûé
QString tmp_string;
sql_str.clear();
// // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
/************************
QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
************************/
// cursor->insertText(tr("Ïðîâåðêà òàáëèöû"));
// *cursor = table->cellAt(0,1).firstCursorPosition();
// cursor->insertText(tr("Ïðîâåðêà òàáëèöû 2"));
// *cursor = table->cellAt(1,1).lastCursorPosition();
// cursor->insertText(tr("Ïðîâåðêà òàáëèöû 4"));
// cursor->movePosition(QTextCursor::End);
//table->cellAt(1,1).firstCursorPosition().insertText(tr("1"));
//table->cellAt(1,2).firstCursorPosition().insertText(tr("2"));
//table->cellAt(2,1).firstCursorPosition().insertText(tr("3"));
//table->cellAt(2,2).firstCursorPosition().insertText(tr("4"));
// cursor->insertText(tr("1 \t 2"));
// cursor->insertText(tr("3 \t 4"));
for(int i=0; i < fieldsNamesList.count(); i++)
{
if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr("íå âîçìîæíî îòîáðàçèòü");
continue;
}
QString fieldType;
fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); //îïðåäåëÿåì òèï ïîëÿ
if(fieldType == tr("pointer")) // åñëè òèï ïîëÿ - óêàçàòåëü
{
QSqlQuery q_tmp;
QString sql_str;
// QString val_str;
QString parent_class_id;// èäåíòèôèêàòîð êëàññà, íà îáúåêòû êîòîðîãî ññûëàåòñÿ ïîëå
QString parent_class_inctance; // õðàíèëèùå îáúåêòîâ ðîäèòåëüñêîãî êëàññà
bool ok;
TField field_tmp;
field_tmp = fieldsMap.value(fieldsNamesList.at(i));
parent_class_id = field_tmp.DefaultValue;
if (parent_class_id.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà
else parent_class_inctance = getClassInctance(parent_class_id);
if (parent_class_inctance.isEmpty()) continue; // íå ñìîãëè îïðåäåëèòü id ðîäèòåëüñêîãî êëàññà
sql_str = tr("select * from `");
sql_str.append(parent_class_inctance);
sql_str.append(tr("` where `ID` = '"));
sql_str.append(q.record().value(i).asString());
sql_str.append(tr("'"));
ok = q_tmp.prepare(sql_str);
ok = q_tmp.exec();
if (!ok) {
QString debug_str;
debug_str.append(tr("ôóí showObjects(): Database Error "));
debug_str.append(tr(" õð: "));
debug_str.append(inctance);
debug_str.append(tr(" ô: "));
debug_str.append(filtr);
debug_str.append(q.lastError().text());
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("ôóíêöèÿ showObjects(): Database Error"), // Çàãîëîâîê.
debug_str
// q.lastError().text()
); // Òåêñò ñîîáùåíèÿ.
return;
}
tmp_string.clear();
while (q_tmp.next()){
tmp_string = q_tmp.record().value(1).asString();
}
fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé
continue;// ïåðåõîäèì ê ñëåäóþùåé èíòåðàöèè
} // äàëüøå åñëè òèï ïîëÿ íå pointer
if(fieldType == tr("file")){ // åñëè òèï ïîëÿ - ôàéë, íå áóäåì îòîáðàæàòü
tmp_string = tr("íå âîçìîæíî îòîáðàçèòü");
continue;
}
tmp_string = q.record().value(i).asString(); // ýòî íå èêîíêà, íå ôàéë è íå ïîëå-óêàçàòåëü, ïðîñòî îòîáðàæàåì çíà÷åíèå
fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// äîáàâëÿåì çíà÷åíèå â ñïèñîê çíà÷åíèé
}
// for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
tableFormat.setAlignment(Qt::AlignLeft);
tableFormat.setBackground(QColor("#e0e0e0"));
// tableFormat.setCellPadding(2);
// tableFormat.setCellSpacing(4);
tableFormat.setLeftMargin(pos*7);
tableFormat.setBorder(1);
tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid);
QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
// table->setFormat(tableFormat);
for(int i=0; i < fieldsValues.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî)
QStringList keys_list = fieldsValues.keys();
QStringList values_list = fieldsValues.values();
*cursor = table->cellAt(i,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé
cursor->insertText(keys_list.at(i), charFormatItalicOnly);//ñþäà çàíîñèì èìÿ ïîëÿ
*cursor = table->cellAt(i,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé
cursor->insertText(values_list.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ
}
// table->setFormat(tableFormat);
cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû
cursor->insertText( tr("\n"));
/******************************
table = cursor->insertTable(fieldsNamesList.count(), 2);// ñîçäàäèì òàáëèöó äëÿ ïîëåé êëàññà, êðîìå ïåðâûõ äâóõ (ID è íàçâàíèå îáúåêòà)
for(int i=2; i < fieldsNamesList.count(); i++){ // ïðîïóñòèì ïîëÿ: ID è ïîëå, ñîäåðæàùåå èìÿ îáúåêòà (îíî è òàê óæå îòîáðàæåíî)
// if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // åñëè ýòî íå èêîíêà, òî ñ÷èòûâàåì çíà÷åíèå êàê ñòðîêó
else tmp_string = tr("íåâîçìîæíî îòîáðàçèòü");
//// if (i !=icon_field_index) {
for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// äîáàâëÿåì ïðîáåëû
*cursor = table->cellAt(i-2,0).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö ïåðâûé
cursor->insertText( fieldsNamesList.at(i));//ñþäà çàíîñèì èìÿ ïîëÿ
*cursor = table->cellAt(i-2,1).firstCursorPosition();// ñòðîêà i-òàÿ, ñòîëáåö âòîðîé
//cursor->insertText( tr(":\t"));
cursor->insertText(tmp_string);//ñþäà çíà÷åíèå ïîëÿ
// cursor->insertText( tr("\n"));
}
//// }
cursor->movePosition(QTextCursor::End);//âûõîäèì èç òàáëèöû
cursor->insertText( tr("\n"));
*********************************/
}
/********************************************************
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
cursor->setBlockFormat(textFormat);
cursor->insertText(tr("Íîâàÿ ñòðàíèöà "));
cursor->insertBlock();
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
cursor->setBlockFormat(textFormat);
**********************************************************/
// itm->setIcon(0, icon);
for (int i=0; i < model_item->childCount(); i++) // ïðîâåðÿåì, åñòü ëè ó êëàññà äî÷åðíèå êëàññû
{
QTreeWidgetItem * model_item_tmp; // åñëè åñòü
QString pointer_name;
QString filtr_tmp;
bool pointer_isEmpty;
model_item_tmp = model_item->child(i); // îòîáðàæàåì îáúåêòû äî÷åðíèõ êëàññîâ
pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1));
// // // // itm->setText(4, pointer_name);
// title_item->setText(4, pointer_name);
pointer_isEmpty = pointer_name.isEmpty();
filtr_tmp = tr("where ");
filtr_tmp.append(tr("`"));
filtr_tmp.append(pointer_name);
filtr_tmp.append(tr("` = '"));
filtr_tmp.append(ID_tmp);
filtr_tmp.append(tr("'"));
printChild(model_item_tmp, filtr_tmp, advanced, pos+1);
// // // // showObjects(itm, model_item_tmp, filtr_tmp);
//MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp);
}
// if(pos==2) newPage(); // åñëè ýòî êîðíåâîé êëàññ, âñòàâèì ðàçäåë ñòðàíèöû
}
}
}
void MainWindow::newPage(int page_number){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó
QTextBlockFormat textFormat;
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
cursor->setBlockFormat(textFormat);
cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number));
cursor->insertBlock();
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
cursor->setBlockFormat(textFormat);
}
void MainWindow::newPage(){ //âñòàâëÿåì â äîêóìåíò íîâóþ ñòðàíèöó
QTextBlockFormat textFormat;
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
cursor->setBlockFormat(textFormat);
//cursor->insertText(tr("Íîâàÿ ñòðàíèöà %1").arg(page_number));
cursor->insertBlock();
textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto);
cursor->setBlockFormat(textFormat);
}
QList<TField> MainWindow::getFieldList(QString class_id){// ïîëó÷àåì ñïèñîê ïîëåé êëàññà
QSqlQuery q;
QString sql_str;
QList<TField> result_list;
int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment;
bool ok;
sql_str = tr("select * "
" from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà
);
sql_str.append(tr("'"));
sql_str.append(class_id);
sql_str.append(tr("' "));
ok = q.prepare(sql_str);
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return result_list;
}
field_id = q.record().indexOf(tr("ID"));
field_name = q.record().indexOf(tr("FieldName"));
field_alias = q.record().indexOf(tr("FieldAlias"));
field_type = q.record().indexOf(tr("FieldType"));
field_default_value = q.record().indexOf(tr("DefaultValue"));
field_classIdentifer = q.record().indexOf(tr("ClassIdentifer"));
field_comment = q.record().indexOf(tr("Comment"));
while(q.next()){
TField field_tmp;
field_tmp.ID = q.value(field_id).toString();
field_tmp.FieldName = q.value(field_name).toString();
field_tmp.FieldAlias = q.value(field_alias).toString();
field_tmp.FieldType = q.value(field_type).toString();
field_tmp.DefaultValue = q.value(field_default_value).toString();
field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString();
field_tmp.Comment = q.value(field_comment).toString();
result_list << field_tmp;
// parentClassID = q.value(field_default_value).toString();
// parentClassInctance = getClassInctance(parentClassID);
// result_map.insert(pointerFieldName, parentClassInctance);
}
return result_list;
}
void MainWindow::readStandartProcessOutput(){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
wmiCursor = new QTextCursor(wmiDoc);
QByteArray arr;
QStringList result, fields, values;
QString str1, str2;
int i;
arr = wmiProcess.readAllStandardOutput();
QTextCodec *codecUTF = QTextCodec::codecForName("utf8");
QTextCodec *codec = QTextCodec::codecForName("cp1251");
QTextCodec::setCodecForTr(codecUTF);
str1 = QString(tr(arr));
result = str1.split("\n", QString::SkipEmptyParts);
if (result.count()>2){
QString tmp_str;
QTextTable * wmi_table;
int fields_count, row_count;
tmp_str = result.at(1);
fields = tmp_str.split("|");
fields_count = fields.count();
row_count = result.count()-1; // ïåðâóþ ñòðîêó (íàçâàíèå êëàññà) îòîáðàæàòü íå áóäåì
wmi_table = wmiCursor->insertTable(row_count, fields_count);
for(int n = 0; n < fields.count(); n++) { // çàïîëíÿåì "øàïêó" òàáëèöû
*wmiCursor = wmi_table->cellAt(0, n).firstCursorPosition();
wmiCursor->insertText(fields.at(n));
}
// tmp_str = result.at(2);
// values = tmp_str.split("|");
for (int m=2; m< result.count(); m++){
tmp_str = result.at(m);
values = tmp_str.split("|");
for(int n = 0; n < values.count(); n++){
*wmiCursor = wmi_table->cellAt(m-1, n).firstCursorPosition();
// wmiCursor->insertText(fields.at(n));
// wmiCursor->insertText(tr(": "));
wmiCursor->insertText(values.at(n));
// wmiCursor->insertText(tr("\n"));
}
}
}
QTextCodec::setCodecForTr(codec);
// result = QStringList(arr);
// str2 << arr;
//i = result.size();
// str1 = result.at(0);
i++;
//lineEdit->insert(str1);
all_reading = true;
}
void MainWindow::readStandartProcessError(){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
wmiCursor = new QTextCursor(wmiDoc);
QString str;
QByteArray arr;
arr = wmiProcess.readAllStandardError();
str = QString(tr(arr));
wmiCursor->insertText(str);
wmiCursor->insertText(tr("\n"));
}
TWmiVideoCard MainWindow::getWmiVideoGard(QString host, QString user_name, QString password){
TWmiVideoCard result;
bool ok;
QString ansver_string;
// wmiThread.moveToThread(&wmiThread);
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("select Name, AdapterCompatibility, AdapterRAM, VideoProcessor from Win32_VideoController"));
wmiThread.start(QThread::NormalPriority);
//for (;;) {if (wmiThread.isStopped()) break;}
int t;
t++;
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
tmp_str = split_new_line.at(2);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("AdapterCompatibility")); // ïðîèçâîäèòåëü
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Name")); // íàçâàíèå âèäåîêàðòû
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("VideoProcessor")); // ìîäåëü
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.model = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("AdapterRAM")); // ìîäåëü
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.video_ram = QVariant(values_list.at(index_tmp)).asInt();
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/*********************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
**********************/
}
/*
QString program = tr("wmic");
QStringList arguments;
// arguments << tr(" -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"");
// program.append(tr(" -U Àäìèíèñòðàòîð%Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\""));
program.append(tr(" -U admin --password=samba //192.168.0.101 \"select * from ")); //Win32_Product\""));
program.append(ui->comboBox_2->currentText());
program.append(tr("\""));
all_reading = false;
int i;
i++;
wmiProcess.start(program);
while (!all_reading){}; //æäåì, ïîêà íå ñ÷èòàåòñÿ ðåçóëüòàò çàïðîñà
*/
return result;
}
TWmiMatherBoard MainWindow::getWmiMatherBoard(QString host, QString user_name, QString password){
TWmiMatherBoard result;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("SELECT Manufacturer, Product FROM Win32_BaseBoard"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
tmp_str = split_new_line.at(2);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Manufacturer")); // ïðîèçâîäèòåëü
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp);
// index_tmp = fields_list.indexOf(tr("Name")); // íàçâàíèå âèäåîêàðòû
// if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Product")); // ìîäåëü
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.model = values_list.at(index_tmp);
// index_tmp = fields_list.indexOf(tr("AdapterRAM")); // ìîäåëü
// if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.video_ram = QVariant(values_list.at(index_tmp)).asInt();
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/***********************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
**********************/
}
return result;
}
TWmiProcessor MainWindow::getWmiProcessor(QString host, QString user_name, QString password){
TWmiProcessor result;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("SELECT Name, Manufacturer, CurrentClockSpeed, SocketDesignation FROM Win32_Processor"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
tmp_str = split_new_line.at(2);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Manufacturer")); // ïðîèçâîäèòåëü ïðîöåññîðà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Name")); // íàçâàíèå ïðîöåññîðà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("SocketDesignation")); // ñîêåò
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.socket = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("CurrentClockSpeed")); // ÷àñòîòà ïðîöåññîðà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.clockSpeed = QVariant(values_list.at(index_tmp)).asInt();
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/************************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
********************/
}
return result;
}
QList<TWmiMemoryModul> MainWindow::getWmiRAM(QString host, QString user_name, QString password)
{
QList<TWmiMemoryModul> result;
TWmiMemoryModul ramModul_tmp;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("SELECT BankLabel, Capacity, Manufacturer from Win32_PhysicalMemory"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
ramModul_tmp.bankLabel = "";
ramModul_tmp.capacity=0;
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("BankLabel")); // Â êàêîé ñëîò óñòàíîâëåí ìîäóëü ïàìÿòè
if ((index_tmp!=-1) && (index_tmp < values_list.count())) ramModul_tmp.bankLabel = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Capacity")); // Ðàçìåð ïàìÿòè
if ((index_tmp!=-1) && (index_tmp < values_list.count())) ramModul_tmp.capacity = QVariant(values_list.at(index_tmp)).asInt();
result << ramModul_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/*********************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
****************/
}
return result;
}
QList<TWmiHDD> MainWindow::getWmiHDD(QString host, QString user_name, QString password)
{
QList<TWmiHDD> result;
TWmiHDD hdd_tmp;
bool ok;
QString ansver_string;
QList<ThddSerialNumber> serNum_list;
serNum_list = MainWindow::getHDDSerNum(host, user_name, password); // îïðåäåëÿåì ñåðèéíûå íîìåðà äèñêîâ
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("SELECT Caption, Manufacturer, Size, DeviceID from Win32_DiskDrive"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
hdd_tmp.caption = "";
hdd_tmp.deviceID="";
hdd_tmp.manufacturer="";
hdd_tmp.serialNumber="";
hdd_tmp.size=0;
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Caption")); // íàçâàíèå äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) hdd_tmp.caption = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Manufacturer")); // ïðîèçâîäèòåëü äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) hdd_tmp.manufacturer = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Size")); // Ðàçìåð äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) {
QString size_str;
bool ok;
size_str = values_list.at(index_tmp);
int size_int=0;
long size_lng;
size_int = size_str.toInt(&ok);
size_lng = size_str.toLong(&ok);
hdd_tmp.size= size_lng;
}
index_tmp = fields_list.indexOf(tr("DeviceID")); // èäåíòèôèêàòîð äèñêà äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) {
hdd_tmp.deviceID = values_list.at(index_tmp);
for (int k=0; k < serNum_list.count(); k++){
if ((serNum_list.at(k).deviceID == hdd_tmp.deviceID)&&(serNum_list.at(k).deviceID !="")) hdd_tmp.serialNumber = serNum_list.at(k).serialNumber;
}
}
result << hdd_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/***********************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
***************************/
}
return result;
}
QList<ThddSerialNumber> MainWindow::getHDDSerNum(QString host, QString user_name, QString password){
QList<ThddSerialNumber> result;
ThddSerialNumber serNum_tmp;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("SELECT SerialNumber, Tag FROM Win32_PhysicalMedia"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
serNum_tmp.serialNumber = "";
serNum_tmp.deviceID = "";
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("SerialNumber")); // ñåðèéíûé íîìåð äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) serNum_tmp.serialNumber = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Tag")); // èäåíòèôèêàòîð äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) serNum_tmp.deviceID = values_list.at(index_tmp);
result << serNum_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
/****************************
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
*************************/
}
}
QList<TWmiCDROM> MainWindow::getWmiCDROM(QString host, QString user_name, QString password)
{
QList<TWmiCDROM> result;
TWmiCDROM cdrom_tmp;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("select Caption, Manufacturer from Win32_CDRomDrive"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
cdrom_tmp.name = "";
cdrom_tmp.manufacturer = "";
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Caption")); // íàèìåíîâàíèå ïðèíòåðà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) cdrom_tmp.name = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("Manufacturer")); // ïðîèçâîäèòåëü äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) cdrom_tmp.manufacturer = values_list.at(index_tmp);
result << cdrom_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
return result;
/*********
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
*******/
}
}
QList<TWmiNetCard> MainWindow::getWmiNetCard(QString host, QString user_name, QString password){
QList<TWmiNetCard> result;
TWmiNetCard netCard_tmp;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("Select Description, Caption, MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
netCard_tmp.caption = "";
netCard_tmp.MACAddress= "";
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Description")); // íàèìåíîâàíèå ïðèíòåðà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) netCard_tmp.caption = values_list.at(index_tmp);
index_tmp = fields_list.indexOf(tr("MACAddress")); // ïðîèçâîäèòåëü äèñêà
if ((index_tmp!=-1) && (index_tmp < values_list.count())) netCard_tmp.MACAddress = values_list.at(index_tmp);
result << netCard_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
return result;
/*********
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
*******/
}
}
QList<TWmiSoundCard> MainWindow::getWmiSoundCard(QString host, QString user_name, QString password)
{
QList<TWmiSoundCard> result;
TWmiSoundCard soundCard_tmp;
bool ok;
QString ansver_string;
wmiThread.setHost(host); // çàäàåì õîñò
wmiThread.setUser(user_name);//çàäàåì èìÿ ïîëüçîâàòåëÿ
wmiThread.setPassword( password);
wmiThread.setWmiString(tr("Select Caption, Name from Win32_SoundDevice"));
wmiThread.start(QThread::NormalPriority);
ok = wmiThread.wait(10000);
if (ok){
QTextDocument * wmiDoc = ui->textEdit_2->document();
QTextCursor * wmiCursor;
QStringList split_new_line; //
QStringList fields_list; //â ýòîì ñïèñêå ñîõðàíèì ïîëÿ
QStringList values_list; //à â ýòîì ñïèñêå - çíà÷åíèÿ
wmiCursor = new QTextCursor(wmiDoc);
ansver_string = wmiThread.resultString();
wmiCursor->insertText(ansver_string);
split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // ðàçáèâàåíì îòâåò íà ñòðîêè
if(split_new_line.count()>2) {
QString tmp_str;
tmp_str = split_new_line.at(1);
fields_list = tmp_str.split("|");
for(int i=2; i< split_new_line.count(); i++)
{
soundCard_tmp.caption = "";
tmp_str = split_new_line.at(i);
values_list = tmp_str.split("|");
int index_tmp;
index_tmp = fields_list.indexOf(tr("Caption")); // íàèìåíîâàíèå çâóêîâîé êàðòû
if ((index_tmp!=-1) && (index_tmp < values_list.count())) soundCard_tmp.caption = values_list.at(index_tmp);
result << soundCard_tmp;
};
return result;
}
else return result; //ïîëó÷èëè íå êîððåêòíûé îòâåò
int m;
m++;
}
else {
wmiThread.terminate();
return result;
/*********
wmiThread.stop();
ok = wmiThread.wait(10000);
int k;
k++;
*******/
}
return result;
}