Хранилища Subversion OpenInventory

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

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

/trunk/ClassEditor/ClassEditor.pro
23,7 → 23,8
delegate.cpp \
modelfordescriptiontable.cpp \
delegateforclassestable.cpp \
modelforpointers.cpp
modelforpointers.cpp \
settingform.cpp
HEADERS += classeditor.h \
mysql.h \
settingsdialog.h \
33,6 → 34,8
delegate.h \
modelfordescriptiontable.h \
delegateforclassestable.h \
modelforpointers.h
modelforpointers.h \
settingform.h
FORMS += classeditor.ui \
settingsdialog.ui
settingsdialog.ui \
settingform.ui
/trunk/ClassEditor/modelforpointers.cpp
79,7 → 79,36
 
QVariant value = QSqlTableModel::data(index, role);
switch (role) {
case Qt::DisplayRole: return value;
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::EditRole: return value;
case Qt::TextColorRole:
if(index.column() == 1)
/trunk/ClassEditor/settingform.ui
Новый файл
0,0 → 1,91
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>settingForm</class>
<widget class="QWidget" name="settingForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>180</width>
<height>306</height>
</rect>
</property>
<property name="windowTitle">
<string>Параметры соединения</string>
</property>
<widget class="QWidget" name="verticalLayout">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>171</width>
<height>336</height>
</rect>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Имя базы данных</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Имя пользователя</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Пароль</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_3"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Имя сервера</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_5"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Применить</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Изменения свойств:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/ClassEditor/settingform.cpp
===================================================================
--- trunk/ClassEditor/settingform.cpp (revision 0)
+++ trunk/ClassEditor/settingform.cpp (revision 134)
@@ -0,0 +1,10 @@
+#include "settingform.h"
+
+// place your code here
+settingForm::settingForm( )
+ : QWidget()
+{
+ setupUi(this);
+
+ // TODO
+}
/trunk/ClassEditor/settingform.cpp
Изменения свойств:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/ClassEditor/settingform.h
===================================================================
--- trunk/ClassEditor/settingform.h (revision 0)
+++ trunk/ClassEditor/settingform.h (revision 134)
@@ -0,0 +1,15 @@
+#ifndef __SETTINGFORM_H__
+#define __SETTINGFORM_H__
+#include <QWidget>
+#include "ui_settingform.h"
+// place your code here
+class settingForm : public QWidget, public Ui::settingForm
+{
+Q_OBJECT
+public:
+ settingForm();
+
+ private slots:
+// void on_pushButton_clicked();
+};
+#endif // __SETTINGFORM_H__
/trunk/ClassEditor/settingform.h
Изменения свойств:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/ClassEditor/delegate.cpp
===================================================================
--- trunk/ClassEditor/delegate.cpp (revision 133)
+++ trunk/ClassEditor/delegate.cpp (revision 134)
@@ -56,6 +56,7 @@
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
: QItemDelegate(parent)
{
+ // SpinBoxDelegate::getItems();
}
//! [0]
@@ -64,10 +65,21 @@
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
- //QSpinBox *editor = new QSpinBox(parent);
- //editor->setMinimum(0);
- //editor->setMaximum(100);
+ QStringList ID_list;
+ QStringList Name_list;
+
+ // getItems();
+
+
+
+
+
+ ID_list = items.keys();
+ Name_list = items.values();
+
QComboBox *editor = new QComboBox(parent);
+
+/*
editor->addItem("0");
editor->addItem("1");
editor->addItem("2");
@@ -78,8 +90,11 @@
editor->addItem("7");
editor->addItem("8");
editor->addItem("9");
- // editor->addItem("0");
+*/
+// editor->addItem("0");
+
+ editor->addItems(Name_list);
return editor;
}
//! [1]
@@ -88,25 +103,33 @@
void SpinBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
- // int value = index.model()->data(index, Qt::EditRole).toInt();
+ QString value = index.model()->data(index, Qt::EditRole).toString();
+ QComboBox *comboBox = static_cast<QComboBox*>(editor);
- // 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);
+ QStringList ID_list;
+ QStringList Name_list;
+ int curr_index;
+ 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);
}
@@ -116,17 +139,21 @@
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
- // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
- // spinBox->interpretText();
- // int value = spinBox->value();
+ QStringList ID_list;
+ QStringList Name_list;
- // model->setData(index, value, Qt::EditRole);
-
QComboBox *comboBox = static_cast<QComboBox*>(editor);
int currIndex;
currIndex = comboBox->currentIndex();
- QString value = comboBox->itemText(currIndex);
+ // QString value = comboBox->itemText(currIndex);
+
+ ID_list = items.keys();
+ Name_list = items.values();
+
+ QString value = ID_list.at(currIndex);
model->setData(index, value, Qt::EditRole);
+
+
}
//! [3]
@@ -137,6 +164,70 @@
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)
@@ -179,3 +270,5 @@
const QModelIndex& /* index */) const {
editor->setGeometry(option.rect);
}
+
+
/trunk/ClassEditor/classeditor.cpp
86,6 → 86,7
QString errorString;
 
sql.setDatabaseName(tr("an_db"));
// sql.setDatabaseName(tr("inventory"));
sql.setHostName(tr("localhost"));
sql.setUserName(tr("an"));
sql.setPassword(tr("393939"));
251,7 → 252,12
*/
ui->tableView_2->setItemDelegateForColumn(3, &classTableDelegate);
 
currIndexOfClassesTable = mymodel->index(0, 1);
delegateForDefaultValueColomn.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &delegateForDefaultValueColomn);
 
 
 
if (mymodel->rowCount() > 0) currIndexOfClassesTable = mymodel->index(0, 1);
QModelIndex index_temp;
 
 
574,8 → 580,8
modelForDescription->setInctance(instance_str); // ïåðåäàåì â ìîäåëü ïîëåé èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
modelForPointers->setInctance(instance_str);
 
delegateForDefaultValueColomn.getItems(); //ïðîñèì äåëåãàòà îáíîâèòü ñïèñîê êëàññîâ
 
 
// instance_str.append(tr("_inctance"));
/*
Inctance_model.clear();
/trunk/ClassEditor/delegate.h
2,9 → 2,11
#define DELEGATE_H
#include <QItemDelegate>
#include <QModelIndex>
#include <QSqlQuery>
#include <QObject>
#include <QSize>
#include <QSpinBox>
#include <QMap>
 
//! [0]
class SpinBoxDelegate : public QItemDelegate
23,6 → 25,13
 
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,6 → 7,7
#include "modelfordescriptiontable.h"
#include "delegateforclassestable.h"
#include "modelforpointers.h"
#include "delegate.h"
 
#include <QTreeView>
 
52,6 → 53,7
QTableView tableForInstance_new; // çäåñü áóäåì îòîáðàæàòü òàáëèöó-õðàíèëèùå îáúåêòîà êëàññà
 
DelegateForClassesTable classTableDelegate;
SpinBoxDelegate delegateForDefaultValueColomn;
 
// void addNewClass(); // äîáàâèì íîâûé êëàññ
void addNewClass_new();