00001 #include <QMessageBox> 00002 00003 #include "newdocumentdialog.h" 00004 #include "../Data/project.h" 00005 #include "../Models/documentchoosermodel.h" 00006 00007 NewDocumentDialog::NewDocumentDialog(DocumentChooserModel *models, QWidget *parent) : QDialog(parent) 00008 { 00009 setupUi(this); 00010 setAttribute(Qt::WA_DeleteOnClose, true); 00011 00012 modelList = models; 00013 00014 connect(buttonBox, SIGNAL(accepted()), this, SLOT(ok())); 00015 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancel())); 00016 00017 listWidgetDocumentTypes->setCurrentRow(0); 00018 } 00019 00020 void NewDocumentDialog::ok() 00021 { 00022 if(listWidgetDocumentTypes->currentItem() != NULL) 00023 { 00024 if(textDocumentName->text() != "" && !checkIfFileExists(textDocumentName->text())) 00025 { 00026 00027 qDebug()<<"Choosen filetype: "<<listWidgetDocumentTypes->currentRow(); 00028 switch(listWidgetDocumentTypes->currentRow()) 00029 { 00030 case WindowType::CostType: 00031 { 00032 createDocument(WindowType::CostType, textDocumentName->text()); 00033 break; 00034 } 00035 case WindowType::CostCentre: 00036 { 00037 createDocument(WindowType::CostCentre, textDocumentName->text()); 00038 break; 00039 } 00040 case WindowType::CostUnit: 00041 { 00042 createDocument(WindowType::CostUnit, textDocumentName->text()); 00043 break; 00044 } 00045 case WindowType::PriceComparison: 00046 { 00047 createDocument(WindowType::PriceComparison, textDocumentName->text()); 00048 break; 00049 } 00050 default: 00051 { 00052 QMessageBox::critical(this, tr("Fehler"), tr("Es trat ein Fehler beim Öffnen des Dokumentes auf - Der Fenstertyp ist nicht verfügbar!")); 00053 break; 00054 } 00055 } 00056 done(0); 00057 } 00058 else 00059 { 00060 QMessageBox::critical(this, tr("Fehler"), tr("Ein Dokument mit diesem Namen existiert bereits! Bitte wählen Sie einen anderen Dateinamen!")); 00061 } 00062 } 00063 else 00064 { 00065 QMessageBox::critical(this, tr("Fehler"), tr("Sie müssen bevor Sie ein Dokument erstellen können den Typ auswählen!")); 00066 } 00067 } 00068 00069 void NewDocumentDialog::cancel() 00070 { 00071 done(1); 00072 } 00073 00074 bool NewDocumentDialog::checkIfFileExists(QString name) 00075 { 00076 return modelList->fileExists(name); 00077 }