ctkDICOMDirectoryListWidget.cpp

Go to the documentation of this file.
00001 
00002 #include <QFileDialog>
00003 #include <QSqlQueryModel>
00004 #include <QSqlTableModel>
00005 #include <QSqlQuery>
00006 #include <QSqlRecord>
00007 #include <QSqlError>
00008 #include <QSqlField>
00009 
00010 
00011 
00012 #include <QDebug>
00013 
00014 // ctkDICOMWidgets includes
00015 #include "ctkDICOMDirectoryListWidget.h"
00016 #include "ui_ctkDICOMDirectoryListWidget.h"
00017 
00018 #include <iostream>
00019 
00020 //----------------------------------------------------------------------------
00021 class ctkDICOMDirectoryListWidgetPrivate: public ctkPrivate<ctkDICOMDirectoryListWidget>,
00022                                      public Ui_ctkDICOMDirectoryListWidget
00023 {
00024 public:
00025   ctkDICOMDirectoryListWidgetPrivate(){}
00026   ctkDICOM* dicom;
00027   QSqlTableModel* directoryListModel;
00028 };
00029 
00030 //----------------------------------------------------------------------------
00031 // ctkDICOMDirectoryListWidgetPrivate methods
00032 
00033 
00034 //---------------------------
00035 // ctkDICOMDirectoryListWidget methods
00036 
00037 //----------------------------------------------------------------------------
00038 ctkDICOMDirectoryListWidget::ctkDICOMDirectoryListWidget(QWidget* _parent):Superclass(_parent)
00039 {
00040   CTK_INIT_PRIVATE(ctkDICOMDirectoryListWidget);
00041   CTK_D(ctkDICOMDirectoryListWidget);
00042 
00043   d->setupUi(this);
00044 
00045   connect(d->addButton, SIGNAL(clicked()), this, SLOT(addDirectoryClicked()));
00046   connect(d->removeButton, SIGNAL(clicked()), this, SLOT(removeDirectoryClicked()));
00047 
00048   d->removeButton->setDisabled(true);
00049 
00050 
00051 
00052 }
00053 
00054 //----------------------------------------------------------------------------
00055 ctkDICOMDirectoryListWidget::~ctkDICOMDirectoryListWidget()
00056 {
00057 }
00058 
00059 //----------------------------------------------------------------------------
00060 void ctkDICOMDirectoryListWidget::addDirectoryClicked()
00061 {
00062   CTK_D(ctkDICOMDirectoryListWidget);
00063   QString newDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"));
00064 
00065   if ( !newDir.isEmpty() )
00066   {
00067     QSqlRecord newDirRecord;
00068     newDirRecord.append(QSqlField("Dirname",QVariant::String));
00069     newDirRecord.setValue("Dirname",newDir);
00070     bool success = d->directoryListModel->insertRecord(-1,newDirRecord);
00071     bool success2 = d->directoryListModel->submitAll();
00072     if ( !success2 )
00073     {
00074       qDebug() << d->directoryListModel->lastError();
00075     }
00076     //addDirectoryQuery.prepare("insert into Directories VALUES ( :dirname )");
00077     //addDirectoryQuery.bindValue(":dirname",newDir);
00078     //addDirectoryQuery.exec();
00079 
00080 //    d->directoryListModel;
00081   }
00082 
00083 //d->directoryListView->setModel(NULL);
00084 // d->tableView->setModel(NULL);
00085 }
00086 
00087 //----------------------------------------------------------------------------
00088 void ctkDICOMDirectoryListWidget::removeDirectoryClicked()
00089 {
00090   CTK_D(ctkDICOMDirectoryListWidget);
00091   while ( ! d->directoryListView->selectionModel()->selectedIndexes().empty() )
00092   {
00093     d->directoryListModel->removeRow(
00094         d->directoryListView->selectionModel()->selectedIndexes().first().row()
00095     );
00096   }
00097 }
00098 
00099 void ctkDICOMDirectoryListWidget::setDICOM(ctkDICOM* dicom)
00100 {
00101   CTK_D(ctkDICOMDirectoryListWidget);
00102   d->dicom = dicom;
00103   d->directoryListModel =  new QSqlTableModel(this,d->dicom->database());
00104   d->directoryListModel->setTable("Directories");
00105   d->directoryListModel->setEditStrategy(QSqlTableModel::OnFieldChange);
00106   d->directoryListModel->select();
00107   d->directoryListView->setModel(d->directoryListModel);
00108 
00109   connect ( d->directoryListView->selectionModel(),
00110             SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
00111             this,
00112             SLOT(directorySelectionChanged(const QItemSelection & , const QItemSelection &  )));
00113 
00114 
00115 }
00116 //----------------------------------------------------------------------------
00117 
00118 void ctkDICOMDirectoryListWidget::directorySelectionChanged( const QItemSelection  & selected, const QItemSelection  & deselected )
00119 {
00120   CTK_D(ctkDICOMDirectoryListWidget);
00121   d->removeButton->setEnabled( ! selected.empty() );
00122 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1