ctkDICOMModel.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QStringList>
  16. #include <QSqlDriver>
  17. #include <QSqlError>
  18. #include <QSqlQuery>
  19. #include <QSqlQueryModel>
  20. #include <QSqlRecord>
  21. #include <QSqlResult>
  22. #include <QTime>
  23. #include <QDebug>
  24. // ctkDICOMCore includes
  25. #include "ctkDICOMModel.h"
  26. #include "ctkLogger.h"
  27. static ctkLogger logger ( "org.commontk.dicom.DICOMModel" );
  28. struct Node;
  29. //------------------------------------------------------------------------------
  30. class ctkDICOMModelPrivate
  31. {
  32. Q_DECLARE_PUBLIC(ctkDICOMModel);
  33. protected:
  34. ctkDICOMModel* const q_ptr;
  35. public:
  36. ctkDICOMModelPrivate(ctkDICOMModel&);
  37. virtual ~ctkDICOMModelPrivate();
  38. void init();
  39. enum IndexType{
  40. RootType,
  41. PatientType,
  42. StudyType,
  43. SeriesType,
  44. ImageType
  45. };
  46. void fetch(const QModelIndex& indexValue, int limit);
  47. Node* createNode(int row, const QModelIndex& parentValue)const;
  48. Node* nodeFromIndex(const QModelIndex& indexValue)const;
  49. //QModelIndexList indexListFromNode(const Node* node)const;
  50. //QModelIndexList modelIndexList(Node* node = 0)const;
  51. //int childrenCount(Node* node = 0)const;
  52. // move it in the Node struct
  53. QVariant value(Node* parentValue, int row, int field)const;
  54. QVariant value(const QModelIndex& indexValue, int row, int field)const;
  55. QString generateQuery(const QString& fields, const QString& table, const QString& conditions = QString())const;
  56. void updateQueries(Node* node)const;
  57. Node* RootNode;
  58. QSqlDatabase DataBase;
  59. QStringList Headers;
  60. QString Sort;
  61. };
  62. //------------------------------------------------------------------------------
  63. // 1 node per row
  64. struct Node
  65. {
  66. ~Node()
  67. {
  68. foreach(Node* node, this->Children)
  69. {
  70. delete node;
  71. }
  72. this->Children.clear();
  73. }
  74. ctkDICOMModelPrivate::IndexType Type;
  75. Node* Parent;
  76. QVector<Node*> Children;
  77. int Row;
  78. QSqlQuery Query;
  79. QString UID;
  80. int RowCount;
  81. bool AtEnd;
  82. bool Fetching;
  83. };
  84. //------------------------------------------------------------------------------
  85. ctkDICOMModelPrivate::ctkDICOMModelPrivate(ctkDICOMModel& o):q_ptr(&o)
  86. {
  87. this->RootNode = 0;
  88. }
  89. //------------------------------------------------------------------------------
  90. ctkDICOMModelPrivate::~ctkDICOMModelPrivate()
  91. {
  92. delete this->RootNode;
  93. this->RootNode = 0;
  94. }
  95. //------------------------------------------------------------------------------
  96. void ctkDICOMModelPrivate::init()
  97. {
  98. this->Headers = QStringList() << "Name" << "Age" << "Scan" << "Date" << "Subject ID"
  99. << "Number" << "Institution" << "Referrer" << "Performer";
  100. }
  101. //------------------------------------------------------------------------------
  102. Node* ctkDICOMModelPrivate::nodeFromIndex(const QModelIndex& indexValue)const
  103. {
  104. return indexValue.isValid() ? reinterpret_cast<Node*>(indexValue.internalPointer()) : this->RootNode;
  105. }
  106. /*
  107. //------------------------------------------------------------------------------
  108. QModelIndexList ctkDICOMModelPrivate::indexListFromNode(const Node* node)const
  109. {
  110. Q_Q(const ctkDICOMModel);
  111. Q_ASSERT(node);
  112. QModelIndexList indexList;
  113. Node* parentNode = node->Parent;
  114. if (parentNode == 0)
  115. {
  116. return indexList;
  117. }
  118. int field = parentNode->Query.record().indexOf("UID");
  119. int row = -1;
  120. for (row = 0; row < parentNode->RowCount; ++row)
  121. {
  122. QString uid = this->value(parentNode, row, field).toString();
  123. if (uid == node->UID)
  124. {
  125. break;
  126. }
  127. }
  128. if (row >= parentNode->RowCount)
  129. {
  130. return indexList;
  131. }
  132. for (int column = 0 ; column < this->Headers.size(); ++column)
  133. {
  134. indexList.append(q->createIndex(row, column, parentNode));
  135. }
  136. return indexList;
  137. }
  138. //------------------------------------------------------------------------------
  139. QModelIndexList ctkDICOMModelPrivate::modelIndexList(Node* node)const
  140. {
  141. QModelIndexList list;
  142. if (node == 0)
  143. {
  144. node = this->RootNode;
  145. }
  146. foreach(Node* child, node->Children)
  147. {
  148. list.append(this->indexListFromNode(child));
  149. }
  150. foreach(Node* child, node->Children)
  151. {
  152. list.append(this->modelIndexList(child));
  153. }
  154. return list;
  155. }
  156. //------------------------------------------------------------------------------
  157. int ctkDICOMModelPrivate::childrenCount(Node* node)const
  158. {
  159. int count = 0;
  160. if (node == 0)
  161. {
  162. node = this->RootNode;
  163. }
  164. count += node->Children.size();
  165. foreach(Node* child, node->Children)
  166. {
  167. count += this->childrenCount(child);
  168. }
  169. return count;
  170. }
  171. */
  172. //------------------------------------------------------------------------------
  173. Node* ctkDICOMModelPrivate::createNode(int row, const QModelIndex& parentValue)const
  174. {
  175. Node* node = new Node;
  176. Node* nodeParent = 0;
  177. if (row == -1)
  178. {// root node
  179. node->Type = ctkDICOMModelPrivate::RootType;
  180. node->Parent = 0;
  181. }
  182. else
  183. {
  184. nodeParent = this->nodeFromIndex(parentValue);
  185. nodeParent->Children.push_back(node);
  186. node->Parent = nodeParent;
  187. node->Type = ctkDICOMModelPrivate::IndexType(nodeParent->Type + 1);
  188. }
  189. node->Row = row;
  190. if (node->Type != ctkDICOMModelPrivate::RootType)
  191. {
  192. int field = 0;//nodeParent->Query.record().indexOf("UID");
  193. node->UID = this->value(parentValue, row, field).toString();
  194. }
  195. node->RowCount = 0;
  196. node->AtEnd = false;
  197. node->Fetching = false;
  198. this->updateQueries(node);
  199. return node;
  200. }
  201. //------------------------------------------------------------------------------
  202. QVariant ctkDICOMModelPrivate::value(const QModelIndex& parentValue, int row, int column) const
  203. {
  204. Node* node = this->nodeFromIndex(parentValue);
  205. if (row >= node->RowCount)
  206. {
  207. const_cast<ctkDICOMModelPrivate *>(this)->fetch(parentValue, row + 256);
  208. }
  209. return this->value(node, row, column);
  210. }
  211. //------------------------------------------------------------------------------
  212. QVariant ctkDICOMModelPrivate::value(Node* parentNode, int row, int column) const
  213. {
  214. if (row < 0 || column < 0 || !parentNode || row >= parentNode->RowCount)
  215. {
  216. return QVariant();
  217. }
  218. if (!parentNode->Query.seek(row))
  219. {
  220. qDebug() << parentNode->Query.lastError();
  221. Q_ASSERT(parentNode->Query.seek(row));
  222. return QVariant();
  223. }
  224. QVariant res = parentNode->Query.value(column);
  225. Q_ASSERT(res.isValid());
  226. return res;
  227. }
  228. //------------------------------------------------------------------------------
  229. QString ctkDICOMModelPrivate::generateQuery(const QString& fields, const QString& table, const QString& conditions)const
  230. {
  231. QString res = QString("SELECT ") + fields + QString(" FROM ") + table;
  232. if (!conditions.isEmpty())
  233. {
  234. res += QString(" WHERE ") + conditions;
  235. }
  236. if (!this->Sort.isEmpty())
  237. {
  238. res += QString(" ORDER BY ") + this->Sort;
  239. }
  240. logger.debug ( "ctkDICOMModelPrivate::generateQuery: query is: " + res );
  241. return res;
  242. }
  243. //------------------------------------------------------------------------------
  244. void ctkDICOMModelPrivate::updateQueries(Node* node)const
  245. {
  246. // are you kidding me, it should be virtualized here :-)
  247. QString query;
  248. switch(node->Type)
  249. {
  250. default:
  251. Q_ASSERT(node->Type == ctkDICOMModelPrivate::RootType);
  252. break;
  253. case ctkDICOMModelPrivate::RootType:
  254. //query = QString("SELECT FROM ");
  255. query = this->generateQuery("UID as UID, PatientsName as Name, PatientsAge as Age, PatientsBirthDate as Date, PatientID as \"Subject ID\"","Patients");
  256. logger.debug ( "ctkDICOMModelPrivate::updateQueries for Root: query is: " + query );
  257. break;
  258. case ctkDICOMModelPrivate::PatientType:
  259. //query = QString("SELECT FROM Studies WHERE PatientsUID='%1'").arg(node->UID);
  260. query = this->generateQuery("StudyInstanceUID as UID, StudyDescription as Name, ModalitiesInStudy as Scan, StudyDate as Date, AccessionNumber as Number, ReferringPhysician as Institution, ReferringPhysician as Referrer, PerformingPhysiciansName as Performer", "Studies",QString("PatientsUID='%1'").arg(node->UID));
  261. logger.debug ( "ctkDICOMModelPrivate::updateQueries for Patient: query is: " + query );
  262. break;
  263. case ctkDICOMModelPrivate::StudyType:
  264. //query = QString("SELECT SeriesInstanceUID as UID, SeriesDescription as Name, BodyPartExamined as Scan, SeriesDate as Date, AcquisitionNumber as Number FROM Series WHERE StudyInstanceUID='%1'").arg(node->UID);
  265. query = this->generateQuery("SeriesInstanceUID as UID, SeriesDescription as Name, BodyPartExamined as Scan, SeriesDate as Date, AcquisitionNumber as Number","Series",QString("StudyInstanceUID='%1'").arg(node->UID));
  266. logger.debug ( "ctkDICOMModelPrivate::updateQueries for Study: query is: " + query );
  267. break;
  268. case ctkDICOMModelPrivate::SeriesType:
  269. //query = QString("SELECT Filename as UID, Filename as Name, SeriesInstanceUID as Date FROM Images WHERE SeriesInstanceUID='%1'").arg(node->UID);
  270. query = this->generateQuery("Filename as UID, Filename as Name, SeriesInstanceUID as Date", "Images", QString("SeriesInstanceUID='%1'").arg(node->UID));
  271. logger.debug ( "ctkDICOMModelPrivate::updateQueries for Series: query is: " + query );
  272. break;
  273. case ctkDICOMModelPrivate::ImageType:
  274. break;
  275. }
  276. node->Query = QSqlQuery(query, this->DataBase);
  277. foreach(Node* child, node->Children)
  278. {
  279. this->updateQueries(child);
  280. }
  281. }
  282. //------------------------------------------------------------------------------
  283. void ctkDICOMModelPrivate::fetch(const QModelIndex& indexValue, int limit)
  284. {
  285. Q_Q(ctkDICOMModel);
  286. Node* node = this->nodeFromIndex(indexValue);
  287. if (node->AtEnd || limit <= node->RowCount || node->Fetching/*|| bottom.column() == -1*/)
  288. {
  289. return;
  290. }
  291. node->Fetching = true;
  292. int newRowCount;
  293. const int oldRowCount = node->RowCount;
  294. // try to seek directly
  295. if (node->Query.seek(limit - 1))
  296. {
  297. newRowCount = limit;
  298. }
  299. else
  300. {
  301. newRowCount = qMax(oldRowCount, 1);
  302. if (node->Query.seek(newRowCount - 1))
  303. {
  304. while (node->Query.next())
  305. {
  306. ++newRowCount;
  307. }
  308. }
  309. else
  310. {
  311. // empty or invalid query
  312. newRowCount = 0;
  313. }
  314. node->AtEnd = true; // this is the end.
  315. }
  316. if (newRowCount > 0 && newRowCount > node->RowCount)
  317. {
  318. q->beginInsertRows(indexValue, node->RowCount, newRowCount - 1);
  319. node->RowCount = newRowCount;
  320. node->Fetching = false;
  321. q->endInsertRows();
  322. }
  323. else
  324. {
  325. node->RowCount = newRowCount;
  326. node->Fetching = false;
  327. }
  328. }
  329. //------------------------------------------------------------------------------
  330. ctkDICOMModel::ctkDICOMModel(QObject* parentObject)
  331. : QAbstractItemModel(parentObject)
  332. , d_ptr(new ctkDICOMModelPrivate(*this))
  333. {
  334. Q_D(ctkDICOMModel);
  335. d->init();
  336. }
  337. //------------------------------------------------------------------------------
  338. ctkDICOMModel::~ctkDICOMModel()
  339. {
  340. }
  341. //------------------------------------------------------------------------------
  342. bool ctkDICOMModel::canFetchMore ( const QModelIndex & parentValue ) const
  343. {
  344. Q_D(const ctkDICOMModel);
  345. Node* node = d->nodeFromIndex(parentValue);
  346. return !node->AtEnd;
  347. }
  348. //------------------------------------------------------------------------------
  349. int ctkDICOMModel::columnCount ( const QModelIndex & _parent ) const
  350. {
  351. Q_D(const ctkDICOMModel);
  352. Q_UNUSED(_parent);
  353. return d->RootNode != 0 ? d->Headers.size() : 0;
  354. }
  355. //------------------------------------------------------------------------------
  356. QVariant ctkDICOMModel::data ( const QModelIndex & dataIndex, int role ) const
  357. {
  358. Q_D(const ctkDICOMModel);
  359. if (role != Qt::DisplayRole && role != Qt::EditRole)
  360. {
  361. return QVariant();
  362. }
  363. QModelIndex parentIndex = this->parent(dataIndex);
  364. Node* parentNode = d->nodeFromIndex(parentIndex);
  365. if (dataIndex.row() >= parentNode->RowCount)
  366. {
  367. const_cast<ctkDICOMModelPrivate *>(d)->fetch(dataIndex, dataIndex.row());
  368. }
  369. int field = parentNode->Query.record().indexOf(d->Headers[dataIndex.column()]);
  370. if (field < 0)
  371. {
  372. // Not all the columns are in the record, it's ok to have no field here.
  373. // Return an empty string in that case (not a QVariant() that means it's
  374. // invalid).
  375. return QString();
  376. }
  377. return d->value(parentIndex, dataIndex.row(), field);
  378. }
  379. //------------------------------------------------------------------------------
  380. void ctkDICOMModel::fetchMore ( const QModelIndex & parentValue )
  381. {
  382. Q_D(ctkDICOMModel);
  383. Node* node = d->nodeFromIndex(parentValue);
  384. d->fetch(parentValue, qMax(node->RowCount, 0) + 256);
  385. }
  386. //------------------------------------------------------------------------------
  387. Qt::ItemFlags ctkDICOMModel::flags ( const QModelIndex & modelIndex ) const
  388. {
  389. Q_UNUSED(modelIndex);
  390. return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
  391. }
  392. //------------------------------------------------------------------------------
  393. bool ctkDICOMModel::hasChildren ( const QModelIndex & parentIndex ) const
  394. {
  395. Q_D(const ctkDICOMModel);
  396. // only items in the first columns have index, shortcut the following for
  397. // speed issues.
  398. if (parentIndex.column() > 0)
  399. {
  400. return false;
  401. }
  402. Node* node = d->nodeFromIndex(parentIndex);
  403. if (!node)
  404. {
  405. return false;
  406. }
  407. // It's not because we don't have row that we don't have children, maybe it
  408. // just means that the children haven't been fetched yet
  409. if (node->RowCount == 0 && !node->AtEnd)
  410. {
  411. // We don't want to fetch the data because we don't want to add children
  412. // to the index yet (it would be a mess to add rows inside a hasChildren)
  413. //const_cast<qCTKDCMTKModelPrivate*>(d)->fetch(parentIndex, 1);
  414. bool res = node->Query.seek(0);
  415. if (!res)
  416. {
  417. // now we know there is no children to the node, don't try next time.
  418. node->AtEnd = true;
  419. }
  420. return res;
  421. }
  422. return node->RowCount > 0;
  423. }
  424. //------------------------------------------------------------------------------
  425. QVariant ctkDICOMModel::headerData(int section, Qt::Orientation orientation, int role)const
  426. {
  427. Q_D(const ctkDICOMModel);
  428. if (role != Qt::DisplayRole &&
  429. role != Qt::EditRole)
  430. {
  431. return QVariant();
  432. }
  433. if (orientation == Qt::Vertical)
  434. {
  435. return section;
  436. }
  437. Q_ASSERT(orientation == Qt::Horizontal);
  438. Q_ASSERT(section < d->Headers.size());
  439. return d->Headers[section];
  440. }
  441. //------------------------------------------------------------------------------
  442. QModelIndex ctkDICOMModel::index ( int row, int column, const QModelIndex & parentIndex ) const
  443. {
  444. Q_D(const ctkDICOMModel);
  445. // only the first column has children
  446. if (d->RootNode == 0 || parentIndex.column() > 0)
  447. {
  448. return QModelIndex();
  449. }
  450. Node* parentNode = d->nodeFromIndex(parentIndex);
  451. int field = 0;// always 0//parentNode->Query.record().indexOf("UID");
  452. QString uid = d->value(parentIndex, row, field).toString();
  453. Node* node = 0;
  454. foreach(Node* tmpNode, parentNode->Children)
  455. {
  456. if (tmpNode->UID == uid)
  457. {
  458. node = tmpNode;
  459. break;
  460. }
  461. }
  462. // TODO: Here it is assumed that ctkDICOMModel::index is called with valid
  463. // arguments, we should probably be a bit more careful.
  464. if (node == 0)
  465. {
  466. node = d->createNode(row, parentIndex);
  467. }
  468. return this->createIndex(row, column, node);
  469. }
  470. //------------------------------------------------------------------------------
  471. QModelIndex ctkDICOMModel::parent ( const QModelIndex & indexValue ) const
  472. {
  473. Q_D(const ctkDICOMModel);
  474. Node* node = d->nodeFromIndex(indexValue);
  475. Q_ASSERT(node);
  476. Node* parentNode = node->Parent;
  477. if (parentNode == 0)
  478. {// node is root
  479. return QModelIndex();
  480. }
  481. return parentNode == d->RootNode ? QModelIndex() : this->createIndex(parentNode->Row, 0, parentNode);
  482. /* need to recalculate the parent row
  483. Node* greatParentNode = parentNode->Parent;
  484. if (greatParentNode == 0)
  485. {
  486. return QModelIndex();
  487. }
  488. int field = greatParentNode->Query.record().indexOf("UID");
  489. int row = -1;
  490. for (row = 0; row < greatParentNode->RowCount; ++row)
  491. {
  492. QString uid = d->value(greatParentNode, row, field).toString();
  493. if (uid == parentNode->UID)
  494. {
  495. break;
  496. }
  497. }
  498. Q_ASSERT(row < greatParentNode->RowCount);
  499. return this->createIndex(row, 0, parentNode);
  500. */
  501. }
  502. //------------------------------------------------------------------------------
  503. int ctkDICOMModel::rowCount ( const QModelIndex & parentValue ) const
  504. {
  505. Q_D(const ctkDICOMModel);
  506. if (d->RootNode == 0 || parentValue.column() > 0)
  507. {
  508. return 0;
  509. }
  510. Node* node = d->nodeFromIndex(parentValue);
  511. Q_ASSERT(node);
  512. // Returns the amount of rows currently cached on the client.
  513. return node ? node->RowCount : 0;
  514. }
  515. //------------------------------------------------------------------------------
  516. void ctkDICOMModel::setDatabase(const QSqlDatabase &db)
  517. {
  518. Q_D(ctkDICOMModel);
  519. this->beginResetModel();
  520. d->DataBase = db;
  521. delete d->RootNode;
  522. d->RootNode = 0;
  523. if (d->DataBase.tables().empty())
  524. {
  525. //Q_ASSERT(d->DataBase.isOpen());
  526. this->endResetModel();
  527. return;
  528. }
  529. d->RootNode = d->createNode(-1, QModelIndex());
  530. this->endResetModel();
  531. // TODO, use hasQuerySize everywhere, not only in setDataBase()
  532. bool hasQuerySize = d->RootNode->Query.driver()->hasFeature(QSqlDriver::QuerySize);
  533. if (hasQuerySize && d->RootNode->Query.size() > 0)
  534. {
  535. int newRowCount= d->RootNode->Query.size();
  536. beginInsertRows(QModelIndex(), 0, qMax(0, newRowCount - 1));
  537. d->RootNode->RowCount = newRowCount;
  538. d->RootNode->AtEnd = true;
  539. endInsertRows();
  540. }
  541. d->fetch(QModelIndex(), 256);
  542. }
  543. //------------------------------------------------------------------------------
  544. void ctkDICOMModel::sort(int column, Qt::SortOrder order)
  545. {
  546. Q_D(ctkDICOMModel);
  547. /* The following would work if there is no fetch involved.
  548. ORDER BY doesn't just apply on the fetched item. By sorting
  549. new items can show up in the model, and we need to be more
  550. careful
  551. emit layoutAboutToBeChanged();
  552. QModelIndexList oldIndexList = d->modelIndexList();
  553. d->Sort = QString("\"%1\" %2")
  554. .arg(d->Headers[column])
  555. .arg(order == Qt::AscendingOrder ? "ASC" : "DESC");
  556. d->updateQueries(d->RootNode);
  557. QModelIndexList newIndexList = d->modelIndexList();
  558. Q_ASSERT(oldIndexList.count() == newIndexList.count());
  559. this->changePersistentIndexList(oldIndexList, newIndexList);
  560. emit layoutChanged();
  561. */
  562. this->beginResetModel();
  563. delete d->RootNode;
  564. d->RootNode = 0;
  565. d->Sort = QString("\"%1\" %2")
  566. .arg(d->Headers[column])
  567. .arg(order == Qt::AscendingOrder ? "ASC" : "DESC");
  568. d->RootNode = d->createNode(-1, QModelIndex());
  569. this->endResetModel();
  570. }
  571. //------------------------------------------------------------------------------
  572. bool ctkDICOMModel::setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role)
  573. {
  574. Q_D(ctkDICOMModel);
  575. if (role != Qt::DisplayRole &&
  576. role != Qt::EditRole)
  577. {
  578. return false;
  579. }
  580. if (orientation == Qt::Vertical)
  581. {
  582. return false;
  583. }
  584. if (value.toString() == d->Headers[section])
  585. {
  586. return false;
  587. }
  588. d->Headers[section] = value.toString();
  589. emit this->headerDataChanged(orientation, section, section);
  590. return true;
  591. }