/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,39 → 108,9 |
case Qt::CheckStateRole: return value; |
case Qt::SizeHintRole: |
{ |
// QSize size(200,100); |
case Qt::SizeHintRole:return value; |
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,12 → 43,6 |
<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,5 → 1,7 |
<?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"> |
6,59 → 8,14 |
<rect> |
<x>0</x> |
<y>0</y> |
<width>177</width> |
<height>70</height> |
<width>400</width> |
<height>300</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> |
<resources/> |
<pixmapfunction/> |
<connections/> |
</ui> |
/trunk/ClassEditor/delegate.cpp |
---|
277,94 → 277,8 |
{ |
} |
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(); |
380,7 → 294,6 |
if (currentImage.isValid()) { |
m_pxPicture.loadFromData(bytes); |
} |
else { |
//QItemDelegate::paint(painter, option, index); |
388,9 → 301,6 |
} |
/* |
if ( !sFileName.isEmpty() ) |
407,8 → 317,6 |
QPalette::Disabled; |
if (option.state & QStyle::State_Selected) |
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
416,7 → 324,7 |
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(); |
428,6 → 336,3 |
} |
void CPictureDelegate::setTableView(QTableView* table){ |
tblView = table; |
} |
/trunk/ClassEditor/iconform.cpp |
---|
1,8 → 1,6 |
#include "iconform.h" |
#include "ui_iconform.h" |
#include "classeditor.h" |
IconForm::IconForm(QWidget *parent) : |
QWidget(parent), |
ui(new Ui::IconForm) |
26,29 → 24,3 |
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,10 → 8,10 |
{ |
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,7 → 1144,6 |
ui->tableView->hideColumn(2); |
CPictureDelegate *pictureDelegate; |
pictureDelegate = new CPictureDelegate(this); |
pictureDelegate->setTableView(ui->tableView); |
ui->tableView->setItemDelegateForColumn(5, pictureDelegate); |
/* |
/trunk/ClassEditor/delegate.h |
---|
7,8 → 7,6 |
#include <QSize> |
#include <QSpinBox> |
#include <QMap> |
#include <QTableView> |
#include "iconform.h" |
//! [0] |
64,36 → 62,12 |
class CPictureDelegate : public QItemDelegate |
{ |
mutable QPixmap m_pxPicture; |
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,19 → 12,12 |
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,7 → 31,6 |
Ui::ClassEditor *ui; |
settingForm setFrm; |
IconForm iconFrm; |
QString baseName; |
QString hostName; |