00001
00002
00003
00004
00005
00006
00007 #include "GeometryModel.h"
00008 #include "GeometryWindow.h"
00009 #include "Logger.h"
00010
00011 const int NO_HIGHLIGHTED_ROW = -1;
00012
00013 GeometryModel::GeometryModel () :
00014 m_rowToBeHighlighted (NO_HIGHLIGHTED_ROW)
00015 {
00016 }
00017
00018 GeometryModel::~GeometryModel()
00019 {
00020 }
00021
00022 QVariant GeometryModel::data(const QModelIndex &index, int role) const
00023 {
00024
00025
00026
00027
00028
00029
00030 if ((role == Qt::BackgroundRole) &&
00031 !m_pointIdentifier.isEmpty () &&
00032 (index.row () == m_rowToBeHighlighted)) {
00033
00034
00035 return QVariant (QColor (230, 230, 230));
00036 }
00037
00038
00039 return QStandardItemModel::data (index, role);
00040 }
00041
00042 int GeometryModel::rowToBeHighlighted () const
00043 {
00044 LOG4CPP_INFO_S ((*mainCat)) << "GeometryModel::rowToBeHighlighted"
00045 << " rows=" << rowCount()
00046 << " cols=" << columnCount();
00047
00048 for (int row = 0; row < rowCount(); row++) {
00049
00050
00051 QModelIndex indexPointIdentifier = index (row,
00052 GeometryWindow::columnBodyPointIdentifiers ());
00053 QVariant var = QStandardItemModel::data (indexPointIdentifier, Qt::DisplayRole);
00054 if (var.isValid()) {
00055 QString pointIdentifierGot = var.toString();
00056 if (pointIdentifierGot == m_pointIdentifier) {
00057
00058
00059 return row;
00060 }
00061 }
00062 }
00063
00064
00065 return NO_HIGHLIGHTED_ROW;
00066 }
00067
00068 void GeometryModel::setCurrentPointIdentifier (const QString &pointIdentifier)
00069 {
00070 LOG4CPP_INFO_S ((*mainCat)) << "GeometryModel::setCurrentPointIdentifier"
00071 << " rows=" << rowCount()
00072 << " cols=" << columnCount()
00073 << " identifier=" << pointIdentifier.toLatin1().data();
00074
00075 m_pointIdentifier = pointIdentifier;
00076
00077 int rowTransitioned;
00078 if (!m_pointIdentifier.isEmpty ()) {
00079
00080
00081 m_rowToBeHighlighted = rowToBeHighlighted();
00082 rowTransitioned = m_rowToBeHighlighted;
00083
00084 } else {
00085
00086
00087 rowTransitioned = m_rowToBeHighlighted;
00088 m_rowToBeHighlighted = NO_HIGHLIGHTED_ROW;
00089
00090 }
00091
00092 QModelIndex indexTopLeft = createIndex (rowTransitioned, 0);
00093 QModelIndex indexBottomRight = createIndex (rowTransitioned, columnCount() - 1);
00094
00095 QVector<int> roles;
00096 roles << Qt::BackgroundRole;
00097
00098 emit dataChanged (indexTopLeft,
00099 indexBottomRight,
00100 roles);
00101 }