Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/dialogs/savedialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com>          *
00003  * Copyright (C) 2007 Stefan Jahn <stefan@lkcc.org>                        *
00004  *                                                                         *
00005  * This is free software; you can redistribute it and/or modify            *
00006  * it under the terms of the GNU General Public License as published by    *
00007  * the Free Software Foundation; either version 2, or (at your option)     *
00008  * any later version.                                                      *
00009  *                                                                         *
00010  * This software is distributed in the hope that it will be useful,        *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
00013  * GNU General Public License for more details.                            *
00014  *                                                                         *
00015  * You should have received a copy of the GNU General Public License       *
00016  * along with this package; see the file COPYING.  If not, write to        *
00017  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,   *
00018  * Boston, MA 02110-1301, USA.                                             *
00019  ***************************************************************************/
00020 
00021 #include "savedialog.h"
00022 #include "qucs.h"
00023 #include "qucsdoc.h"
00024 
00025 #include <QVariant>
00026 #include <QLabel>
00027 #include <QPushButton>
00028 #include <QHBoxLayout>
00029 #include <QVBoxLayout>
00030 #include <QDebug>
00031 #include <QGroupBox>
00032 #include <QListWidgetItem>
00033 
00034 SaveDialog::SaveDialog( QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
00035    : QDialog( parent, name, modal, fl ),unsavedDocs()
00036 {
00037    if ( !name )
00038       setWindowTitle( tr( "Save the modified files" ) );
00039    app = 0l;
00040    initDialog();
00041 }
00042 
00043 SaveDialog::~SaveDialog()
00044 {
00045 }
00046 
00047 void SaveDialog::setApp(QucsApp *a)
00048 {
00049    app = a;
00050 }
00051 
00052 void SaveDialog::initDialog()
00053 {
00054    setSizeGripEnabled( FALSE );
00055    SaveDialogLayout = new QVBoxLayout( this, 11, 6, "SaveDialogLayout"); 
00056 
00057    label = new QLabel( tr( "Select files to be saved" ) );
00058    SaveDialogLayout->addWidget( label );
00059 
00060    QGroupBox *group = new QGroupBox( tr( "Modified Files" ) );
00061    QVBoxLayout *checkBoxLayout = new QVBoxLayout();
00062    group->setLayout(checkBoxLayout);
00063    
00064    fileView = new QListWidget(this);
00065    checkBoxLayout->addWidget(fileView);
00066    SaveDialogLayout->addWidget(group);
00067    
00068    buttonsLayout = new QHBoxLayout( 0, 0, 6, "buttonsLayout"); 
00069 
00070    abortClosingButton = new QPushButton( tr( "Abort Closing" ) );
00071    buttonsLayout->addWidget( abortClosingButton );
00072    spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00073    buttonsLayout->addItem( spacer );
00074 
00075    dontSaveButton = new QPushButton( tr( "Don't Save" ) );
00076    buttonsLayout->addWidget( dontSaveButton );
00077 
00078    saveSelectedButton = new QPushButton( tr( "Save Selected" ) );
00079    saveSelectedButton->setDefault(true);
00080    buttonsLayout->addWidget( saveSelectedButton );
00081    SaveDialogLayout->addLayout( buttonsLayout );
00082    languageChange();
00083    resize( QSize(500, 300).expandedTo(minimumSizeHint()) );
00084    //clearWState( Qt::WA_WState_Polished );
00085    setAttribute(Qt::WA_WState_Polished, false);
00086 
00087    connect(abortClosingButton,SIGNAL(clicked()),this,SLOT(reject()));
00088    connect(dontSaveButton,SIGNAL(clicked()),this,SLOT(dontSaveClicked()));
00089    connect(saveSelectedButton,SIGNAL(clicked()),this,SLOT(saveSelectedClicked()));
00090 }
00091 
00092 void SaveDialog::addUnsavedDoc(QucsDoc *doc)
00093 {
00094    QString text = (doc->DocName).isEmpty() ? tr("Untitled") : doc->DocName;
00095 
00096    QListWidgetItem *item = new QListWidgetItem(text, fileView);
00097    item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
00098    item->setCheckState(Qt::Checked);
00099    
00100    unsavedDocs.insert(doc, item);
00101 }
00102 
00103 void SaveDialog::dontSaveClicked()
00104 {
00105    done(DontSave);
00106 }
00107 
00108 void SaveDialog::saveSelectedClicked()
00109 {   
00110    QList<QucsDoc*> unsavable;
00111    QMap<QucsDoc*,QListWidgetItem*>::iterator it(unsavedDocs.begin());
00112    for ( ; it != unsavedDocs.end(); ++it)
00113    {
00114       if ( it.value()->checkState() == Qt::Checked )
00115       {
00116          QucsDoc *doc = static_cast<QucsDoc*>(it.key());
00117          if(app->saveFile(doc) == false)
00118             unsavable.append(doc);
00119          else
00120             unsavedDocs.remove(it);
00121       }
00122    }
00123    if(unsavable.isEmpty())
00124        done(SaveSelected);
00125 }
00126 
00127 void SaveDialog::reject()
00128 {
00129    done(AbortClosing);
00130 }
00131 
00132 bool SaveDialog::isEmpty() const
00133 {
00134    return unsavedDocs.isEmpty();
00135 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines