Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 164 → Rev 165

/trunk/ClassEditor/delegate.cpp
277,16 → 277,102
{
}
 
 
 
 
 
QWidget *CPictureDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
 
IconForm *editor = new IconForm(parent);
return editor;
 
}
 
 
 
 
void CPictureDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
 
 
const QAbstractItemModel * model = index.model();
IconForm *icnFrm = static_cast<IconForm*>(editor);
QVariant currentImage = model->data(index,0);
QByteArray bytes = currentImage.toByteArray();
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
}
else {
//QItemDelegate::paint(painter, option, index);
return;
}
icnFrm->setPixmap(m_pxPicture);
}
 
 
 
 
void CPictureDelegate::setModelData(
QWidget *editor,
QAbstractItemModel *model,
const QModelIndex& index) const {
IconForm *icnFrm = static_cast<IconForm*>(editor);
m_pxPicture = icnFrm->pixmap();
QImage currentImage = m_pxPicture.toImage();
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
currentImage.save(&buffer, "PNG");
 
 
 
 
model->setData(index, QVariant (bytes), Qt::EditRole);
 
// int widht = m_pxPicture.width();
// int heigh = m_pxPicture.height();
// tblView->setRowHeight(index.row(), heigh + 10);
// model->submitAll();
 
 
 
 
// model->setData(index, value);
}
 
 
 
void CPictureDelegate::updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex& /* index */) const {
 
 
// QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
// editor->setGeometry(r);
 
editor->setGeometry(option.rect);
}
 
 
 
 
void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
m_pxPicture.fill( QColor(Qt::white) );
 
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
 
QVariant currentImage = model->data(index,0);
m_pxPicture.fill( QColor(Qt::white) );
 
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
 
QVariant currentImage = model->data(index,0);
 
 
QByteArray bytes = currentImage.toByteArray();
// QImage image;
// image.loadFromData(bytes);
294,6 → 380,7
 
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
 
}
else {
//QItemDelegate::paint(painter, option, index);
301,6 → 388,9
}
 
 
 
 
 
/*
 
if ( !sFileName.isEmpty() )
317,14 → 407,16
QPalette::Disabled;
 
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
 
 
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
 
int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
painter->drawPixmap( nX, nY, m_pxPicture );
 
 
//// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
 
/*
QPen pen = painter->pen();
333,6 → 425,9
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->setPen(pen);
*/
}
}
 
 
void CPictureDelegate::setTableView(QTableView* table){
tblView = table;
}
/trunk/ClassEditor/iconform.cpp
1,6 → 1,8
#include "iconform.h"
#include "ui_iconform.h"
#include "classeditor.h"
 
 
IconForm::IconForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::IconForm)
24,3 → 26,29
break;
}
}
 
 
void IconForm::on_pushButton_clicked(){ // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ïîìåíÿòü èêîíêó"
 
QString fileName;
fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
 
if (fileName.isEmpty()) return;
Pixmap.load(fileName);
 
ui->label->setPixmap(Pixmap);
// IconForm::close();
}
 
 
void IconForm::setPixmap (QPixmap newPixmap){
Pixmap = newPixmap;
ui->label->setPixmap(Pixmap);
 
}
 
 
QPixmap IconForm::pixmap (){
return Pixmap;
}
/trunk/ClassEditor/classeditor.cpp
8,8 → 8,8
{
ui->setupUi(this);
 
iconFrm.show();
 
 
readSettings();
1137,7 → 1137,7
mymodel->setHeaderData(5, Qt::Horizontal, tr("Èêîíêà"));
ui->tableView->setModel(mymodel);
ui->tableView->setAlternatingRowColors(true);
ui->tableView->resizeColumnsToContents();
// ui->tableView->resizeColumnsToContents();
 
ui->tableView->hideColumn(0);
ui->tableView->hideColumn(3);
1144,6 → 1144,7
ui->tableView->hideColumn(2);
CPictureDelegate *pictureDelegate;
pictureDelegate = new CPictureDelegate(this);
pictureDelegate->setTableView(ui->tableView);
ui->tableView->setItemDelegateForColumn(5, pictureDelegate);
 
/*
/trunk/ClassEditor/delegate.h
7,6 → 7,8
#include <QSize>
#include <QSpinBox>
#include <QMap>
#include <QTableView>
 
#include "iconform.h"
 
//! [0]
62,12 → 64,36
class CPictureDelegate : public QItemDelegate
{
mutable QPixmap m_pxPicture;
public:
private:
QTableView *tblView;
 
public:
CPictureDelegate( QObject *parent );
 
QWidget *createEditor(
QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setEditorData(QWidget *editor,
const QModelIndex &index) const;
 
void setModelData(QWidget *editor,
QAbstractItemModel *model,
const QModelIndex &index) const;
 
 
void updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setTableView(QTableView* table);
 
 
//QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
 
/trunk/ClassEditor/iconform.h
12,12 → 12,19
public:
IconForm(QWidget *parent = 0);
~IconForm();
 
void setPixmap (QPixmap newPixmap);
QPixmap pixmap ();
protected:
void changeEvent(QEvent *e);
 
private:
Ui::IconForm *ui;
QPixmap Pixmap;
private slots:
 
void on_pushButton_clicked(); // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ïîìåíÿòü èêîíêó"
 
 
};
 
#endif // ICONFORM_H
/trunk/ClassEditor/classeditor.h
31,6 → 31,7
Ui::ClassEditor *ui;
 
settingForm setFrm;
IconForm iconFrm;
 
QString baseName;
QString hostName;
/trunk/ClassEditor/mymodel.cpp
9,13 → 9,13
Qt::ItemFlags MyModel::flags(
const QModelIndex &index) const {
Qt::ItemFlags flags = QSqlTableModel::flags(index);
if ((index.column() != 3) && (index.column() != 0) && (index.column() != 5))
if ((index.column() != 3) && (index.column() != 0) /* && (index.column() != 5)*/)
flags |= Qt::ItemIsEditable;
//if (index.column() == 4)
// flags |= Qt::ItemIsUserCheckable;
else
{
if ((index.column() == 3) || (index.column() == 0) || (index.column() == 5)) flags &= ~Qt::ItemIsEditable; // çàïðåùàåì ðåäàêòèðîâàíèå 0, 3 è 5 ñòîëáöà
if ((index.column() == 3) || (index.column() == 0) /* || (index.column() == 5)*/) flags &= ~Qt::ItemIsEditable; // çàïðåùàåì ðåäàêòèðîâàíèå 0, 3 è 5 ñòîëáöà
}
return flags;
}
108,9 → 108,39
 
case Qt::CheckStateRole: return value;
 
case Qt::SizeHintRole:return value;
case Qt::SizeHintRole:
{
// QSize size(200,100);
 
}
return value;
// return QVariant(size);
}
 
case Qt::DecorationRole: {
/* if(index.column() == 5) {
QVariant currentImage = QSqlTableModel::data(index, 0);
QByteArray bytes = currentImage.toByteArray();
QPixmap pxmp;
if (currentImage.isValid()) {
pxmp.loadFromData(bytes);
QIcon icon;
icon.addPixmap(pxmp);
return icon;
 
}
else {
//QItemDelegate::paint(painter, option, index);
return value;
}
 
}
*/
 
}
 
 
 
}
return value;
}
 
/trunk/ClassEditor/classeditor.ui
43,6 → 43,12
<height>192</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
/trunk/ClassEditor/iconform.ui
1,7 → 1,5
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>IconForm</class>
<widget class="QWidget" name="IconForm">
<property name="geometry">
8,14 → 6,59
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>177</width>
<height>70</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>111</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Поменять</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>111</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Сохранить</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>120</x>
<y>0</y>
<width>81</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>pc.png</pixmap>
</property>
</widget>
</widget>
<pixmapfunction/>
<resources/>
<connections/>
</ui>