27 #include "../../../common/Exception.h"
28 #include "../../../common/CharEncodingConv.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/dataset/ObjectIdSet.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../datatype/Enums.h"
33 #include "../../../datatype/SimpleData.h"
34 #include "../../../memory/DataSet.h"
35 #include "../../../memory/DataSetItem.h"
42 #include <QMessageBox>
44 bool IsPkey(
const int& column,
const std::vector<size_t>& pkeys)
46 std::vector<size_t>::const_iterator it;
48 for(it=pkeys.begin(); it!=pkeys.end(); ++it)
61 return QObject::tr(
"Void");
65 return QObject::tr(
"Bit");
69 return QObject::tr(
"Char");
73 return QObject::tr(
"Unsigned char");
79 return QObject::tr(
"Integer");
85 return QObject::tr(
"Unsigned integer");
89 return QObject::tr(
"Boolean");
93 return QObject::tr(
"Float");
97 return QObject::tr(
"Double");
101 return QObject::tr(
"Numeric");
105 return QObject::tr(
"String");
109 return QObject::tr(
"Byte array");
113 return QObject::tr(
"Geometry");
117 return QObject::tr(
"Date time");
121 return QObject::tr(
"Unknown");
139 void setValue(
const int& row,
const int& column,
const std::string& value)
141 std::pair<int, int> key(row, column);
145 bool isEdited(
const int& row,
const int& column)
const
150 std::string
getValue(
const int& row,
const int& column)
152 return m_editions[std::pair<int, int>(row, column)];
162 std::vector<int> rows;
167 for(
int i = 0; i < (int)rows.size(); ++i)
170 std::set<int> ef = fields[i];
177 bool edited = ef.find(j) != ef.end();
183 std::string data =
getValue(rows[i], j);
227 for(
int i = init; i <=
final; i++)
233 std::map< std::pair<int, int>, std::string > aux;
234 std::map< std::pair<int, int>, std::string >::iterator it;
238 int cE = it->first.second;
243 std::pair<int, int> rC = it->first;
245 if(rC.second > column)
248 aux[rC] = it->second;
258 std::vector< std::set<int> > res;
262 std::set<int> subRes;
263 int current =
m_editions.begin()->first.first;
264 rows.push_back(current);
265 std::map< std::pair<int, int>, std::string >::iterator it;
269 int cR = it->first.first;
274 res.push_back(subRes);
279 subRes.insert(it->first.second);
282 if(rows.size() != res.size())
283 res.push_back(subRes);
293 : QAbstractTableModel(parent),
326 m_rowCount = (m_dataset == 0 || !m_enabled) ? 0 : (
int)m_dataset->size();
333 m_pkeysColumns = pkeys;
340 m_promoter->promote(oids);
352 m_OIdsVisible = visible;
360 std::vector<size_t>::iterator it;
362 for(it=m_pkeysColumns.begin(); it!=m_pkeysColumns.end(); ++it)
363 oids->
addProperty(m_dataset->getPropertyName(*it), *it, m_dataset->getPropertyDataType(*it));
368 for(
int i=initRow; i<=finalRow; i++)
370 row = (int)m_promoter->getLogicalRow(i);
371 m_dataset->move(row);
387 m_rowCount = (m_enabled && m_dataset != 0) ? (
int)m_dataset->size() : 0;
394 m_isEditable = editable;
399 std::auto_ptr<te::da::DataSet> dset;
402 m_editor->getEditedDataSet(m_dataset, md, ps);
411 return m_editor->hasEditions();
426 return (m_dataset == 0) ? 0 : (int) m_dataset->getNumProperties();
436 case Qt::TextAlignmentRole:
437 return (
int)(Qt::AlignCenter);
440 case Qt::DisplayRole:
442 if(m_currentRow != index.row())
444 m_currentRow = index.row();
446 int row = (int)m_promoter->getLogicalRow(m_currentRow);
447 m_dataset->move(row);
450 if(m_editor->isEdited(m_promoter->getLogicalRow(index.row()), index.column()))
452 std::string f = m_editor->getValue(m_promoter->getLogicalRow(index.row()), index.column()).c_str();
457 if(m_dataset->isNull(index.column()))
462 std::string value = m_dataset->getString(index.column());
465 return value.c_str();
470 return m_dataset->getAsString(index.column(), 6).c_str();
475 if(m_editor->isEdited(m_promoter->getLogicalRow(index.row()), index.column()))
485 return data(index, Qt::DisplayRole);
497 if(orientation == Qt::Horizontal)
501 case Qt::DisplayRole:
502 return m_dataset->getPropertyName(section).c_str();
505 case Qt::DecorationRole:
506 return (m_OIdsVisible &&
IsPkey(section, m_pkeysColumns)) ?
507 QIcon::fromTheme(
"key") :
511 case Qt::ToolTipRole:
512 return m_dataset->getPropertyName(section).c_str() + QString(
" : ") +
ColumnType(m_dataset->getPropertyDataType(section));
516 return QAbstractTableModel::headerData(section, orientation, role);
524 case Qt::DisplayRole:
529 return QAbstractTableModel::headerData(section, orientation, role);
539 if (index.isValid() ==
false)
542 Qt::ItemFlags flags = QAbstractItemModel::flags(index);
544 flags |= Qt::ItemIsEnabled | Qt::ItemIsSelectable;
546 if(m_isEditable && !
IsPkey(index.column(), m_pkeysColumns))
547 flags |= Qt::ItemIsEditable;
554 if(role == Qt::EditRole)
558 switch(m_dataset->getPropertyDataType(index.column()))
588 QString curV = data(index, Qt::DisplayRole).toString();
589 QString newV = value.toString();
594 std::string out = c.
conv(newV.toStdString());
595 m_editor->setValue(m_promoter->getLogicalRow(index.row()), index.column(), out);
602 QMessageBox::warning(0, tr(
"Edition Failure"), e.
what());
612 beginInsertColumns(parent, column, column+count);
621 beginRemoveColumns(parent, column, column+count);
623 m_editor->columnsRemoved(column, column+count);
std::string getValue(const int &row, const int &column)
A model based on te::da::DataSet.
CharEncoding
Supported charsets (character encoding).
std::map< std::pair< int, int >, std::string > m_editions
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
A class that models the description of a dataset.
virtual const char * what() const
It outputs the exception message.
This class deals with character encoding/decoding.
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
void addProperty(const std::string &name, std::size_t pos, int type)
It adds a property that will be used to generate the unique ids.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void getEditedDataSet(te::da::DataSet *in, te::mem::DataSet *out, std::vector< std::set< int > > &fields)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
void setExpressionByInClause(const std::string source="")
std::vector< std::set< int > > getEditedLists(std::vector< int > &rows)
bool IsPkey(const int &column, const std::vector< size_t > &pkeys)
std::string conv(const std::string &src)
It converts the source string to a target charset.
void columnRemoved(const int &column)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void columnsRemoved(const int &init, const int &final)
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
A dataset is the unit of information manipulated by the data access module of TerraLib.
bool isEdited(const int &row, const int &column) const
const std::vector< std::string > & getPropertyNames() const
It returns the property names used to generated the oids.
void add(ObjectId *oid)
It adds an object id to this object id set.
A template for atomic data types (integers, floats, strings and others).
void setValue(const int &row, const int &column, const std::string &value)
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
QString ColumnType(const int &type)