Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 136 → Rev 137

/trunk/ClassEditor/classeditor.cpp
10,13 → 10,13
 
// settdialog = new SettingsDialog(this);
///////////////////////////////////////////////////// settdialog.show();
 
 
readSettings();
 
// sql.setDatabaseName(tr("an_db"));
 
initDataBase(); // íàñòðàèâàåì è óñòàíàâëèâàåì ñîåäèíåíèå
createMainTables(); // ñîçäàåì ñòðóêòóðó íàøåé áàçû - äâå ãëàâíûå òàáëèöû DescriptionOfClasses è ListOfClasses
 
 
 
91,44 → 91,9
 
QString errorString;
 
// sql.setDatabaseName(tr("an_db"));
 
sql.setDatabaseName(baseName);
// sql.setDatabaseName(tr("inventory"));
 
// 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.connect();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Connect"), // Çàãîëîâîê.
QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ.
 
 
 
 
 
}
 
/*
ok = sql.createTable(table);
if (!ok) {
149,49 → 114,9
 
*/
 
ok = sql.createListOfClassesTable();
 
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Create"), // Çàãîëîâîê.
QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
}
 
 
 
 
ok = sql.createDescriptionOfClassesTable();
 
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Create"), // Çàãîëîâîê.
QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
}
 
 
 
 
 
 
 
model = new QSqlTableModel(); // õðàíèëèùå îáúåêòîâ êëàññà
tableForInstance = new QTableView();
mymodel = new MyModel(this);
201,18 → 126,22
modelForDescription = new ModelForDescriptionTable(this);
 
 
 
initClassListTable();
 
initFieldsTable();
 
initPointersTable();
 
/////////////////model->setTable(tr("ListOfClasses"));
mymodel->setTable(tr("ListOfClasses"));
modelForDescription->setTable(tr("DescriptionOfClasses"));
modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange);
 
 
 
/////model->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
// modelForPointers->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange);
 
modelForPointers->setTable(tr("DescriptionOfClasses"));
 
 
 
222,44 → 151,19
 
 
//////////////////model->setSort(0, Qt::AscendingOrder);
mymodel->setSort(0, Qt::AscendingOrder);
modelForDescription->setSort(0, Qt::AscendingOrder);
modelForPointers->setSort(0, Qt::AscendingOrder);
 
// model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
////////////////////model->select();
mymodel->select();
// modelForPointers->select();
 
 
 
// model->setFilter(tr("Èäåíòèôèêàòîð_ñèñòåìíîãî_áëîêà = '7' and Èíâåíòàðíûé_íîìåð = 'i09090909'"));
////////////////////model->select();
 
/////////////////////////model->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
//tableForDescription = new QTableView();
 
 
 
////////////////////////model->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé"));
 
//ui->tableView_3->setModel(modelForPointers);
 
//ui->tableView->setModel(model);
ui->tableView->setModel(mymodel);
//tableForDescription = new QTableView();
ui->tableView_2->setModel(modelForDescription);
ui->tableView_2->setAlternatingRowColors(true);
ui->tableView_2->resizeColumnsToContents();
//tableForDescription->show();
 
 
ui->tableView->setAlternatingRowColors(true);
ui->tableView->resizeColumnsToContents();
 
ui->tableView->hideColumn(0);
ui->tableView->hideColumn(3);
ui->tableView->hideColumn(2);
 
/*
ui->tableView_2->hideColumn(0);
266,18 → 170,21
ui->tableView_2->hideColumn(5);
ui->tableView_2->hideColumn(2);
*/
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
 
delegateForDefaultValueColomn.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
 
 
 
if (mymodel->rowCount() > 0) {
 
 
//if (mymodel->rowCount() > 0) {
 
currIndexOfClassesTable = mymodel->index(0, 1);
 
 
/*
 
currIndexOfClassesTable = mymodel->index(0, 1);
 
 
QModelIndex index_temp;
 
 
301,6 → 208,9
class_instance = mymodel->data(mymodel->index(0,3)).toString();
 
currInctanceTable = class_instance; //
 
 
 
modelForDescription->setInctance(class_instance); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
//class_instance.append(tr("_inctance"));
str_fltr.append(class_indx);
330,11 → 240,10
 
modelForPointers->setFilter(str_fltr);
modelForPointers->select();
ui->tableView_3->setModel(modelForPointers);
ui->tableView_3->resizeColumnsToContents();
 
}
 
*/
 
//connect(ui->tableView, SIGNAL(clicked(const QModelIndex)), this, SLOT(on_tableView_clicked(const QModelIndex)));
connect(mymodel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_myModel_dataChanged(QModelIndex,QModelIndex)));
connect(modelForDescription, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_modelForDescription_dataChanged(QModelIndex,QModelIndex)));
625,8 → 534,10
}
 
void ClassEditor::on_tableView_clicked(const QModelIndex & index ){
bool indexIsValid;
int i, row, column;
i++;
indexIsValid = index.isValid();
row = index.row();
column = index.column();
currIndexOfClassesTable = index;
1099,5 → 1010,122
 
void ClassEditor::initDataBase(){ // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ
 
sql.setDatabaseName(baseName);
sql.setHostName(hostName);
sql.setUserName(userName);
sql.setPassword(password);
 
bool ok;
ok = sql.connect();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Connect"), // Çàãîëîâîê.
QObject::tr("Ñîåäèíåíèå ñ áàçîé äàííûõ óñïåøíî óñòàíîâëåíî.")); // Òåêñò ñîîáùåíèÿ.
 
 
 
 
 
}
 
}
 
 
void ClassEditor::createMainTables(){// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses
 
bool ok;
ok = sql.createListOfClassesTable();
 
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Create"), // Çàãîëîâîê.
QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
}
 
 
 
 
ok = sql.createDescriptionOfClassesTable();
 
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
sql.lasError()); // Òåêñò ñîîáùåíèÿ.
 
}
else {
 
QMessageBox::information( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Create"), // Çàãîëîâîê.
QObject::tr("Áàçà äàííûõ óñïåøíî ñîçäàíà.")); // Òåêñò ñîîáùåíèÿ.
}
 
 
 
 
 
 
 
}
 
void ClassEditor::initClassListTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ
 
mymodel->setTable(tr("ListOfClasses"));
mymodel->setSort(0, Qt::AscendingOrder);
mymodel->select();
mymodel->setHeaderData(1, Qt::Horizontal, tr("Èìÿ êëàññà"));
mymodel->setHeaderData(2, Qt::Horizontal, tr("Ïñåâäîíèì êëàññà"));
mymodel->setHeaderData(4, Qt::Horizontal, tr("Êîìåíòàðèé"));
ui->tableView->setModel(mymodel);
ui->tableView->setAlternatingRowColors(true);
ui->tableView->resizeColumnsToContents();
 
ui->tableView->hideColumn(0);
ui->tableView->hideColumn(3);
ui->tableView->hideColumn(2);
}
 
 
void ClassEditor::initFieldsTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé ñóùåñòâóþùèõ êëàññîâ
 
modelForDescription->setTable(tr("DescriptionOfClasses"));
modelForDescription->setSort(0, Qt::AscendingOrder);
modelForDescription->setEditStrategy(QSqlTableModel::OnFieldChange);
ui->tableView_2->setModel(modelForDescription);
ui->tableView_2->setAlternatingRowColors(true);
ui->tableView_2->resizeColumnsToContents();
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
}
 
void ClassEditor::initPointersTable(){ // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà
 
modelForPointers->setTable(tr("DescriptionOfClasses"));
modelForPointers->setSort(0, Qt::AscendingOrder);
modelForPointers->setEditStrategy(QSqlTableModel::OnFieldChange);
ui->tableView_3->setModel(modelForPointers);
delegateForDefaultValueColomn.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
 
// ui->tableView_3->resizeColumnsToContents();
 
}
/trunk/ClassEditor/classeditor.h
76,8 → 76,11
void addNewPointer();//äîáîâëÿåì íîâîå ïîëå, ãäå áóäóò õðàíèòüñÿ óêàçàòåëè íà îáúåêòû êëàññà-êîíòåéíåðà
void refreshInctance(); // îáíîâèì ìîäåëü òàáëèöû-õðàíèëèùà
void initDataBase(); // íàñòðîéêà ïàðàìåòðîâ ñîåäèíåíèÿ è óñòàíîâêà ñîåäèíåíèÿ
void createMainTables();// ñîçäàåì ñòðóêòóðó áàçû äàííûõ - òàáëèöû DescriptionOfClasses è ListOfClasses
void initClassListTable(); // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ñóùåñòâóþùèõ êëàññîâ
void initFieldsTable(); // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé êëàññà
void initPointersTable(); // íàñòðàèâàåì òàáëèöó äëÿ îòîáðàæåíèÿ ñïèñêà ïîëåé-óêàçàòåëåé êëàññà
 
 
private slots:
 
void on_pushButton_clicked(); // îáðàáîò÷èê íàæàòèÿ êíîïêè "Íîâûé êëàññ"
/trunk/ClassEditor/delegateforclassestable.cpp
8,7 → 8,7
items.append(tr("CHAR(30)"));
items.append(tr("INT(10)"));
items.append(tr("DATE"));
items.append(tr("TYFTA"));
items.append(tr("BLOB"));
}
QWidget *DelegateForClassesTable::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,