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