Хранилища Subversion OpenInventory

Сравнить редакции

Не учитывать пробелы Редакция 134 → Редакция 133

/trunk/ClassEditor/settingform.ui
Файл удален
/trunk/ClassEditor/settingform.cpp
Файл удален
/trunk/ClassEditor/settingform.h
Файл удален
/trunk/ClassEditor/delegate.cpp
56,7 → 56,6
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
: QItemDelegate(parent)
{
// SpinBoxDelegate::getItems();
}
//! [0]
 
65,21 → 64,10
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QStringList ID_list;
QStringList Name_list;
 
// getItems();
 
 
 
 
 
ID_list = items.keys();
Name_list = items.values();
 
//QSpinBox *editor = new QSpinBox(parent);
//editor->setMinimum(0);
//editor->setMaximum(100);
QComboBox *editor = new QComboBox(parent);
 
/*
editor->addItem("0");
editor->addItem("1");
editor->addItem("2");
90,11 → 78,8
editor->addItem("7");
editor->addItem("8");
editor->addItem("9");
*/
// editor->addItem("0");
 
// editor->addItem("0");
 
editor->addItems(Name_list);
return editor;
}
//! [1]
103,33 → 88,25
void SpinBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
// int value = index.model()->data(index, Qt::EditRole).toInt();
 
QStringList ID_list;
QStringList Name_list;
int curr_index;
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// spinBox->setValue(value);
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
if (value == "0") comboBox->setCurrentIndex(0);
if (value == "1") comboBox->setCurrentIndex(1);
if (value == "2") comboBox->setCurrentIndex(2);
if (value == "3") comboBox->setCurrentIndex(3);
if (value == "4") comboBox->setCurrentIndex(4);
if (value == "5") comboBox->setCurrentIndex(5);
if (value == "6") comboBox->setCurrentIndex(6);
if (value == "7") comboBox->setCurrentIndex(7);
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
comboBox->setEditable(true);
 
ID_list = items.keys();
Name_list = items.values();
 
curr_index = ID_list.indexOf(value);
comboBox->setCurrentIndex(curr_index);
/****************************************************
if (value == "0") comboBox->setCurrentIndex(0);
if (value == "1") comboBox->setCurrentIndex(1);
if (value == "2") comboBox->setCurrentIndex(2);
if (value == "3") comboBox->setCurrentIndex(3);
if (value == "4") comboBox->setCurrentIndex(4);
if (value == "5") comboBox->setCurrentIndex(5);
if (value == "6") comboBox->setCurrentIndex(6);
if (value == "7") comboBox->setCurrentIndex(7);
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
******************************************************/
comboBox->setEditable(true);
 
 
//comboBox->setItemText(0, value);
 
}
139,21 → 116,17
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QStringList ID_list;
QStringList Name_list;
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// spinBox->interpretText();
// int value = spinBox->value();
 
// model->setData(index, value, Qt::EditRole);
 
QComboBox *comboBox = static_cast<QComboBox*>(editor);
int currIndex;
currIndex = comboBox->currentIndex();
// QString value = comboBox->itemText(currIndex);
 
ID_list = items.keys();
Name_list = items.values();
 
QString value = ID_list.at(currIndex);
QString value = comboBox->itemText(currIndex);
model->setData(index, value, Qt::EditRole);
 
 
}
//! [3]
 
164,70 → 137,6
editor->setGeometry(option.rect);
}
//! [4]
 
void SpinBoxDelegate::getItems(){
QMap <QString, QString> result_map;
QSqlQuery q;
QString query_str;
bool ok;
 
query_str = tr("select * from `ListOfClasses`");
q.prepare(query_str);
 
 
ok = q.exec();
 
 
 
 
if (!ok) {
/*
QString error_str;
error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
error_str.append(inctance);
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
// tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
 
*/
items.clear();
return;
}
 
 
// field_inctance = q.record().indexOf(tr("TableWhithInstance"));
items.clear();
while(q.next()){
 
QString ID;
QString ClassName;
ID = q.value(0).toString(); // îïðåäåëÿåì ID
ClassName = q.value(1).toString(); // îïðåäåëÿåì Name
items.insert(ID, ClassName);
}
 
 
// return result_map;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
MyDEDelegate::MyDEDelegate(
bool calpopup,
QObject *parent)
270,5 → 179,3
const QModelIndex& /* index */) const {
editor->setGeometry(option.rect);
}
 
 
/trunk/ClassEditor/classeditor.cpp
86,7 → 86,6
QString errorString;
 
sql.setDatabaseName(tr("an_db"));
// sql.setDatabaseName(tr("inventory"));
sql.setHostName(tr("localhost"));
sql.setUserName(tr("an"));
sql.setPassword(tr("393939"));
252,12 → 251,7
*/
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
 
delegateForDefaultValueColomn.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
 
 
 
if (mymodel->rowCount() > 0) currIndexOfClassesTable = mymodel->index(0, 1);
currIndexOfClassesTable = mymodel->index(0, 1);
QModelIndex index_temp;
 
 
580,8 → 574,8
modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
modelForPointers->setInctance(instance_str);
 
delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ
 
 
// instance_str.append(tr("_inctance"));
/*
Inctance_model.clear();
/trunk/ClassEditor/delegate.h
2,11 → 2,9
#define DELEGATE_H
#include <QItemDelegate>
#include <QModelIndex>
#include <QSqlQuery>
#include <QObject>
#include <QSize>
#include <QSpinBox>
#include <QMap>
 
//! [0]
class SpinBoxDelegate : public QItemDelegate
25,13 → 23,6
 
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
 
void getItems(); // ïîëó÷àåì ñâÿçàííûé ñïèñîê
 
private:
QMap <QString, QString> items; // çäåñü áóäåì õðàíèòü ñâÿçàííûé ñïèñîê èìåò îáúåêòîâ è èõ èäåíòèôèêàòîðîâ ID
 
 
};
//! [0]
 
/trunk/ClassEditor/classeditor.h
7,7 → 7,6
#include "modelfordescriptiontable.h"
#include "delegateforclassestable.h"
#include "modelforpointers.h"
#include "delegate.h"
 
#include <QTreeView>
 
53,7 → 52,6
QTableView tableForInstance_new; // çäåñü áóäåì îòîáðàæàòü òàáëèöó-õðàíèëèùå îáúåêòîà êëàññà
 
DelegateForClassesTable classTableDelegate;
SpinBoxDelegate delegateForDefaultValueColomn;
 
// void addNewClass(); // äîáàâèì íîâûé êëàññ
void addNewClass_new();
/trunk/ClassEditor/ClassEditor.pro
23,8 → 23,7
delegate.cpp \
modelfordescriptiontable.cpp \
delegateforclassestable.cpp \
modelforpointers.cpp \
settingform.cpp
modelforpointers.cpp
HEADERS += classeditor.h \
mysql.h \
settingsdialog.h \
34,8 → 33,6
delegate.h \
modelfordescriptiontable.h \
delegateforclassestable.h \
modelforpointers.h \
settingform.h
modelforpointers.h
FORMS += classeditor.ui \
settingsdialog.ui \
settingform.ui
settingsdialog.ui
/trunk/ClassEditor/modelforpointers.cpp
79,36 → 79,7
 
QVariant value = QSqlTableModel::data(index, role);
switch (role) {
case Qt::DisplayRole: {
if(index.column() == 4){
QSqlQuery q;
QString sql_str;
bool ok;
sql_str = tr("select * from `ListOfClasses` where `ID` = ");
sql_str.append(value.toString());
 
q.prepare(sql_str);
 
ok = q.exec();
 
if (ok) {
while(q.next()){
QString class_name = q.value(1).toString();
if (!class_name.isEmpty()) return class_name;
 
}
 
 
}
 
}
 
 
return value;
}
 
 
 
case Qt::DisplayRole: return value;
case Qt::EditRole: return value;
case Qt::TextColorRole:
if(index.column() == 1)