Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 83 → Rev 84

/trunk/ClassEditor/modelforpointers.cpp
New file
0,0 → 1,114
#include "modelforpointers.h"
 
ModelForPointers::ModelForPointers(QObject *parent) :
QSqlTableModel(parent)
{
setEditStrategy(QSqlTableModel::OnManualSubmit);
}
 
Qt::ItemFlags ModelForPointers::flags(
const QModelIndex &index) const {
Qt::ItemFlags flags = QSqlTableModel::flags(index);
if ((index.column() != 3) && (index.column() != 0))
flags |= Qt::ItemIsEditable;
//if (index.column() == 4)
// flags |= Qt::ItemIsUserCheckable;
else
{
if ((index.column() == 3) || (index.column() == 0)) flags &= ~Qt::ItemIsEditable; // çàïðåùàåì ðåäàêòèðîâàíèå òðåòüåãî ñòîëáöà
}
return flags;
}
 
 
bool ModelForPointers::setData(const QModelIndex &index, const QVariant &value, int role) {
//// if (index.column()==3) return false; // â òðåòüåé êîëîíêå íå äàåì ïîìåíÿòü çíà÷åíèå
bool lResult = false;
 
 
lResult = QSqlTableModel::setData(index, value, role);
if (lResult) {
QModelIndex newindex;
QSqlRecord rec = record(index.row());
 
rec.setValue(index.column(), value);
rec.setGenerated(index.column(), true);
 
 
lResult = updateRowInTable(index.row(), rec);
/// QSqlTableModel::setData(newindex, QVariant(str_tmp), Qt::EditRole);
 
 
}
return lResult;
}
 
 
 
QVariant ModelForPointers::data(const QModelIndex &index, int role) const {
 
QVariant value = QSqlTableModel::data(index, role);
switch (role) {
case Qt::DisplayRole: return value;
case Qt::EditRole: return value;
case Qt::TextColorRole:
if(index.column() == 1)
return qVariantFromValue(QColor(Qt::blue));
else
return value;
case Qt::TextAlignmentRole: return value;
case Qt::FontRole:
if(index.column() == 1) {
QFont font = QFont("Helvetica", 16, QFont::Bold);
return qVariantFromValue(font);
}else
return value;
 
case Qt::BackgroundColorRole: {
int a = (index.row() % 2) ? 14 : 0;
if(index.column() == 2)
return qVariantFromValue(QColor(220,240-a,230-a));
else if(index.column() == 4)
return qVariantFromValue(QColor(200,220-a,255-a));
else
return value;
}
 
 
 
case Qt::CheckStateRole: return value;
 
case Qt::SizeHintRole:return value;
 
}
return value;
}
 
void ModelForPointers::setInctance(QString currInctatce){ // ïåðåäàåì èìÿ òåêóùåé òàáëèöû-õðàíèëèùà
ModelForPointers::Inctance = currInctatce;
}
 
 
bool ModelForPointers::onlySetData(const QModelIndex &index, const QVariant &value, int role){
bool lResult = false;
 
QSqlRecord rec = record(index.row());
rec.setValue(index.column(), value);
rec.setGenerated(index.column(), true);
 
 
lResult = QSqlTableModel::setData(index, value, role);
if (lResult) {
lResult = updateRowInTable(index.row(), rec);
// emit field_changed();
/// QSqlTableModel::setData(newindex, QVariant(str_tmp), Qt::EditRole);
}
 
 
 
 
return lResult;
 
}