Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 227 → Rev 228

/trunk/DBViewer/mainwindow.cpp
119,6 → 119,11
 
// fileForm.show();
 
 
cursor = new QTextCursor(&doc);
buildReport(true);
 
 
}
 
MainWindow::~MainWindow()
949,9 → 954,11
 
 
 
conditionList.clear();
conditionList <<"" << ")";
filterConditionDelegate_2.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2);
 
 
 
ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate);
 
 
1002,3 → 1009,301
 
 
}
 
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("test.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;
 
model_name = model_item->text(0);
if (model_item->checkState(0) == false) return; // ìîäåëü íå âûäåëåíà äëÿ îòîáðàæåíèÿ
 
 
if (!(model_item->childCount() > 0)) return; // ìîäåëü ïóñòà (íå ñîäåðæèò êëàññîâ)
 
rootClassID = model_item->child(0)->text(1);
rootClassInctance = getClassInctance(rootClassID);
 
cursor->insertText(model_name);
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;
QFont font;
QIcon icon;
 
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;
 
 
cursor->insertText(className);
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"));
 
 
 
 
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; i++){ cursor->insertText( tr("\t"));}// äîáàâëÿåì ïðîáåëû
cursor->insertImage(fname);
// cursor->insertText(tr("\n"));
 
}
 
 
 
 
// // // icn.addPixmap(pix);
// // // itm->setIcon(0, icn);
// }
 
 
 
}
 
for(int i=0; i<pos; i++){ cursor->insertText( tr("\t"));}// äîáàâëÿåì ïðîáåëû
 
cursor->insertText( value_tmp);
cursor->insertText( tr("\n"));
 
// 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("'"));
// // // // showObjects(itm, model_item_tmp, filtr_tmp);
//MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp);
 
}
 
 
}
 
}
 
 
 
 
 
 
 
 
 
 
}
 
 
/trunk/DBViewer/mainwindow.h
161,6 → 161,15
 
int getIconFieldIndex(QString inctance); // ïîëó÷àåì íîìåð ñòîëáöà ñ èêîíêàìè
 
 
void buildReport(bool advanced); // ñîçäàåì îò÷åò è ýêñïîðòèðóåì â OpenOffice, ïåðåìåííàÿ advanced óêàçûâàåò áóäåò ëè îò÷åò ðàñøèðåííûì
// QTreeWidgetItem * model_item
 
void getReport(QTreeWidgetItem * model_item, bool advanced); // ñîçäàåò îò÷åò äëÿ êîíêðåòíîé ìîäåëè ïåðåìåííàÿ advanced óêàçûâàåò áóäåò ëè îò÷åò ðàñøèðåííûì
 
void printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos);//â ðàïîðò äîáàâëÿåì äî÷åðíèå êëàññû
 
 
SpinBoxDelegate spinDelegate;
QItemDelegate standart_delegate;
CPictureDelegate * picture_delegate;
175,10 → 184,11
 
QMap <QString, QPixmap> classesIcons;
 
QTextDocument doc;
QTextCursor * cursor;
 
 
 
 
private slots:
void on_comboBox_currentIndexChanged( int index );
void on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column );