Sfoglia il codice sorgente

ctkDICOMModel now support checkable header views

It doesn't support yet the checkstaterole on the model items, just the
headers.
Julien Finet 15 anni fa
parent
commit
5d566df3ca

+ 35 - 20
Libs/DICOM/Core/ctkDICOMModel.cpp

@@ -71,7 +71,7 @@ public:
 
 
   Node*        RootNode;
   Node*        RootNode;
   QSqlDatabase DataBase;
   QSqlDatabase DataBase;
-  QStringList  Headers;
+  QList<QMap<int, QVariant> > Headers;
   QString      Sort;
   QString      Sort;
 };
 };
 
 
@@ -114,8 +114,25 @@ ctkDICOMModelPrivate::~ctkDICOMModelPrivate()
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 void ctkDICOMModelPrivate::init()
 void ctkDICOMModelPrivate::init()
 {
 {
-  this->Headers = QStringList() << "Name" << "Age" << "Scan" << "Date" << "Subject ID"
-                  << "Number" << "Institution" << "Referrer" << "Performer";
+  QMap<int, QVariant> data;
+  data[Qt::DisplayRole] = QString("Name");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Age");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Scan");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Date");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Subject ID");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Number");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Institution");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Referrer");
+  this->Headers << data;
+  data[Qt::DisplayRole] = QString("Performer");
+  this->Headers << data;
 }
 }
 
 
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
@@ -406,7 +423,8 @@ QVariant ctkDICOMModel::data ( const QModelIndex & dataIndex, int role ) const
     {      
     {      
     const_cast<ctkDICOMModelPrivate *>(d)->fetch(dataIndex, dataIndex.row());
     const_cast<ctkDICOMModelPrivate *>(d)->fetch(dataIndex, dataIndex.row());
     }
     }
-  int field = parentNode->Query.record().indexOf(d->Headers[dataIndex.column()]);
+  QString columnName = d->Headers[dataIndex.column()][Qt::DisplayRole].toString();
+  int field = parentNode->Query.record().indexOf(columnName);
   if (field < 0)
   if (field < 0)
     {
     {
     // Not all the columns are in the record, it's ok to have no field here.
     // Not all the columns are in the record, it's ok to have no field here.
@@ -469,18 +487,19 @@ bool ctkDICOMModel::hasChildren ( const QModelIndex & parentIndex ) const
 QVariant ctkDICOMModel::headerData(int section, Qt::Orientation orientation, int role)const
 QVariant ctkDICOMModel::headerData(int section, Qt::Orientation orientation, int role)const
 {
 {
   Q_D(const ctkDICOMModel);
   Q_D(const ctkDICOMModel);
-  if (role != Qt::DisplayRole &&
-      role != Qt::EditRole)
-    {
-    return QVariant();
-    }
   if (orientation == Qt::Vertical)
   if (orientation == Qt::Vertical)
     {
     {
+    if (role != Qt::DisplayRole)
+      {
+      return QVariant();
+      }
     return section;
     return section;
     }
     }
-  Q_ASSERT(orientation == Qt::Horizontal);
-  Q_ASSERT(section < d->Headers.size());
-  return d->Headers[section];
+  if (section < 0 || section >= d->Headers.size())
+    {
+    return QVariant();
+    }
+  return d->Headers[section][role];
 }
 }
 
 
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
@@ -618,7 +637,7 @@ void ctkDICOMModel::sort(int column, Qt::SortOrder order)
   delete d->RootNode;
   delete d->RootNode;
   d->RootNode = 0;
   d->RootNode = 0;
   d->Sort = QString("\"%1\" %2")
   d->Sort = QString("\"%1\" %2")
-    .arg(d->Headers[column])
+    .arg(d->Headers[column][Qt::DisplayRole].toString())
     .arg(order == Qt::AscendingOrder ? "ASC" : "DESC");
     .arg(order == Qt::AscendingOrder ? "ASC" : "DESC");
   d->RootNode = d->createNode(-1, QModelIndex());
   d->RootNode = d->createNode(-1, QModelIndex());
   
   
@@ -629,20 +648,16 @@ void ctkDICOMModel::sort(int column, Qt::SortOrder order)
 bool ctkDICOMModel::setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role)
 bool ctkDICOMModel::setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role)
 {
 {
   Q_D(ctkDICOMModel);
   Q_D(ctkDICOMModel);
-  if (role != Qt::DisplayRole &&
-      role != Qt::EditRole)
-    {
-    return false;
-    }
   if (orientation == Qt::Vertical)
   if (orientation == Qt::Vertical)
     {
     {
     return false;
     return false;
     }
     }
-  if (value.toString() == d->Headers[section])
+  if (section < 0 || section >= d->Headers.size() ||
+      d->Headers[section][role] == value)
     {
     {
     return false;
     return false;
     }
     }
-  d->Headers[section] = value.toString();
+  d->Headers[section][role] = value;
   emit this->headerDataChanged(orientation, section, section);
   emit this->headerDataChanged(orientation, section, section);
   return true;
   return true;
 }
 }

+ 1 - 1
Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.cpp

@@ -124,7 +124,7 @@ void ctkDICOMQueryRetrieveWidget::processQuery()
       }
       }
     }
     }
   }
   }
-
+  
   // checkable headers - allow user to select the patient/studies to retrieve
   // checkable headers - allow user to select the patient/studies to retrieve
   d->results->setModel(&d->model);
   d->results->setModel(&d->model);
   d->model.setDatabase(d->queryResultDatabase.database());
   d->model.setDatabase(d->queryResultDatabase.database());