This file is indexed.

/usr/include/tulip/cxx/TulipItemEditorCreators.cxx is in libtulip-dev 4.4.0dfsg2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */
#include <sstream>
#include <QSet>
#include <QLineEdit>
#include <QTextEdit>
#include <QComboBox>
#include <QPainter>

#include <tulip/ForEach.h>
#include <tulip/DataSet.h>
#include <tulip/VectorEditionWidget.h>
#include <tulip/GraphPropertiesModel.h>


namespace tlp {

template<typename T>
QWidget* LineEditEditorCreator<T>::createWidget(QWidget *parent) const {
  return new QLineEdit(parent);
}

template<typename T>
void LineEditEditorCreator<T>::setEditorData(QWidget* editor, const QVariant &data,bool,tlp::Graph*) {
  typename T::RealType val = data.value<typename T::RealType>();
  static_cast<QLineEdit*>(editor)->setText(QString::fromUtf8(T::toString(val).c_str()));
  static_cast<QLineEdit*>(editor)->selectAll();
}

template<typename T>
QVariant LineEditEditorCreator<T>::editorData(QWidget* editor,tlp::Graph*) {
  std::string strVal = std::string(static_cast<QLineEdit*>(editor)->text().toUtf8().data());
  QVariant result;
  typename T::RealType val;

  if (T::fromString(val,strVal))
    result.setValue<typename T::RealType>(val);

  return result;
}

template<typename T>
QWidget* MultiLinesEditEditorCreator<T>::createWidget(QWidget *parent) const {
  QTextEdit *edit = new QTextEdit(parent);
  edit->setFocusPolicy(Qt::StrongFocus);
  edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  return edit;
}

template<typename T>
void MultiLinesEditEditorCreator<T>::setEditorData(QWidget* editor, const QVariant &data,bool,tlp::Graph*) {
  typename T::RealType val = data.value<typename T::RealType>();
  static_cast<QTextEdit*>(editor)->setPlainText(QString::fromUtf8(T::toString(val).c_str()));
  static_cast<QTextEdit*>(editor)->selectAll();
}

template<typename T>
QVariant MultiLinesEditEditorCreator<T>::editorData(QWidget* editor,tlp::Graph*) {
  std::string strVal = std::string(static_cast<QTextEdit*>(editor)->toPlainText().toUtf8().data());
  QVariant result;
  typename T::RealType val;

  if (T::fromString(val,strVal))
    result.setValue<typename T::RealType>(val);

  return result;
}

template<typename T>
QSize MultiLinesEditEditorCreator<T>::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const {
  QVariant data = index.model()->data(index);
  typename T::RealType val = data.value<typename T::RealType>();
  QString valS = QString::fromUtf8(T::toString(val).c_str());
  QStringList lines = valS.split(QLatin1Char('\n'));
  QFontMetrics fontMetrics(option.font);
  int height = 0;
  int width = 0;

  for (int i = 0 ; i < lines.count() ; ++i) {
    QRect textBB = fontMetrics.boundingRect(lines.at(i));
    height += textBB.height();
    width = std::max(width, textBB.width());
  }

  return QSize(width+15, height+5);
}

template<typename T>
bool MultiLinesEditEditorCreator<T>::paint(QPainter* painter, const QStyleOptionViewItem &option, const QVariant &data) const {
  TulipItemEditorCreator::paint(painter,option,data);
  QRect rect = option.rect;
  typename T::RealType val = data.value<typename T::RealType>();
  QString valS = QString::fromUtf8(T::toString(val).c_str());
  QStringList lines = valS.split(QLatin1Char('\n'));

  if (option.state.testFlag(QStyle::State_Selected) && option.showDecorationSelected) {
    painter->setPen(option.palette.highlightedText().color());
    painter->setBrush(option.palette.highlightedText());
  }
  else {
    painter->setPen(option.palette.text().color());
    painter->setBrush(option.palette.text());
  }

  for (int i = 0 ; i < lines.count() ; ++i) {
    painter->drawText(rect.x(), rect.y() + i * rect.height()/lines.count(), rect.width(), rect.height()/lines.count(),Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap, lines.at(i));
  }

  return true;
}

template<typename PROPTYPE>
QWidget* PropertyEditorCreator<PROPTYPE>::createWidget(QWidget* parent) const {
  return new QComboBox(parent);
}

template<typename PROPTYPE>
void PropertyEditorCreator<PROPTYPE>::setEditorData(QWidget* w, const QVariant& val,bool isMandatory,tlp::Graph* g) {
  if (g == NULL) {
    w->setEnabled(false);
    return;
  }

  PROPTYPE* prop = val.value<PROPTYPE*>();
  QComboBox* combo = static_cast<QComboBox*>(w);
  GraphPropertiesModel<PROPTYPE>* model = NULL;

  if (isMandatory)
    model = new GraphPropertiesModel<PROPTYPE>(g,false,combo);
  else
    model = new GraphPropertiesModel<PROPTYPE>(QObject::trUtf8("Select a property"),g,false,combo);

  combo->setModel(model);
  combo->setCurrentIndex(model->rowOf(prop));
}

template<typename PROPTYPE>
QVariant PropertyEditorCreator<PROPTYPE>::editorData(QWidget* w,tlp::Graph* g) {
  if (g == NULL)
    return QVariant();

  QComboBox* combo = static_cast<QComboBox*>(w);
  GraphPropertiesModel<PROPTYPE>* model = static_cast<GraphPropertiesModel<PROPTYPE> *>(combo->model());
  QVariant var = model->data(model->index(combo->currentIndex(),0),TulipModel::PropertyRole);
  tlp::PropertyInterface* pi = var.value<tlp::PropertyInterface*>();
  PROPTYPE* prop = (PROPTYPE*)(pi);
  return QVariant::fromValue<PROPTYPE*>(prop);
}

template<typename PROPTYPE>
QString PropertyEditorCreator<PROPTYPE>::displayText(const QVariant& v) const {
  PROPTYPE *prop = v.value<PROPTYPE*>();

  if (prop==NULL)
    return QObject::trUtf8("Select a property");

  return QString::fromUtf8(prop->getName().c_str());
}

template<typename ElementType>
QWidget* VectorEditorCreator<ElementType>::createWidget(QWidget*) const {
  VectorEditionWidget* w = new VectorEditionWidget(NULL);
  w->setWindowFlags(Qt::Dialog);
  w->setWindowModality(Qt::ApplicationModal);
  return w;

}

template<typename ElementType>
void VectorEditorCreator<ElementType>::setEditorData(QWidget* editor, const QVariant& v,bool,tlp::Graph*) {
  QVector<QVariant> editorData;
  std::vector<ElementType> vect = v.value<std::vector<ElementType> >();

  for (size_t i=0; i < vect.size(); ++i)  {
    editorData.push_back(QVariant::fromValue<ElementType>(vect[i]));
  }

  static_cast<VectorEditionWidget*>(editor)->setVector(editorData,qMetaTypeId<ElementType>());

  static_cast<VectorEditionWidget*>(editor)->move(QCursor::pos());
}

template<typename ElementType>
QVariant VectorEditorCreator<ElementType>::editorData(QWidget* editor,tlp::Graph*) {
  std::vector<ElementType> result;
  QVector<QVariant> editorData = static_cast<VectorEditionWidget*>(editor)->vector();
  foreach(QVariant v, editorData)
  result.push_back(v.value<ElementType>());
  return QVariant::fromValue<std::vector<ElementType> >(result);
}

// the template below is only used for displayText method implementation
template<typename T>
struct DisplayVectorDataType :public DataType {
  DisplayVectorDataType(void *value) :DataType(value) {}
  ~DisplayVectorDataType() {
  }
  DataType* clone() const {
    return NULL;
  }

  std::string getTypeName() const {
    return std::string(typeid(std::vector<T>).name());
  }
};


template<typename ElementType>
QString VectorEditorCreator<ElementType>::displayText(const QVariant &data) const {
  std::vector<ElementType> v = data.value<std::vector<ElementType> >();

  if (v.empty())
    return QString();

  // use a DataTypeSerializer if any
  DataTypeSerializer* dts =
    DataSet::typenameToSerializer(std::string(typeid(v).name()));

  if (dts) {
    DisplayVectorDataType<ElementType> dt(&v);

    std::stringstream sstr;
    dts->writeData(sstr, &dt);

    std::string str = sstr.str();

    if (str.size() > 45)
      str.replace(str.begin() + 41, str.end(), " ...)");

    return QString::fromUtf8(str.c_str());
  }

  if (v.size() == 1)
    return QString("1 element");

  return QString::number(v.size()) + QObject::trUtf8(" elements");
}

}