Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
savedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> *
3  * Copyright (C) 2007 Stefan Jahn <stefan@lkcc.org> *
4  * *
5  * This is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2, or (at your option) *
8  * any later version. *
9  * *
10  * This software is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this package; see the file COPYING. If not, write to *
17  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, *
18  * Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "savedialog.h"
22 #include "qucs.h"
23 #include "qucsdoc.h"
24 
25 #include <QVariant>
26 #include <QLabel>
27 #include <QPushButton>
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QDebug>
31 
32 SaveDialog::SaveDialog( QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
33  : QDialog( parent, name, modal, fl ),unsavedDocs()
34 {
35  if ( !name )
36  setWindowTitle( tr( "Save the modified files" ) );
37  app = 0l;
38  initDialog();
39 }
40 
42 {
43 }
44 
46 {
47  app = a;
48 }
49 
51 {
52  setSizeGripEnabled( FALSE );
53  SaveDialogLayout = new QVBoxLayout( this, 11, 6, "SaveDialogLayout");
54 
55  label = new QLabel( tr( "Select files to be saved" ) );
56  SaveDialogLayout->addWidget( label );
57 
58  QGroupBox *group = new QGroupBox( tr( "Modified Files" ) );
59  QVBoxLayout *checkBoxLayout = new QVBoxLayout();
60  group->setLayout(checkBoxLayout);
61 
62  fileView = new QListWidget(this);
63  checkBoxLayout->addWidget(fileView);
64  SaveDialogLayout->addWidget(group);
65 
66  buttonsLayout = new QHBoxLayout( 0, 0, 6, "buttonsLayout");
67 
68  abortClosingButton = new QPushButton( tr( "Abort Closing" ) );
69  buttonsLayout->addWidget( abortClosingButton );
70  spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
71  buttonsLayout->addItem( spacer );
72 
73  dontSaveButton = new QPushButton( tr( "Don't Save" ) );
74  buttonsLayout->addWidget( dontSaveButton );
75 
76  saveSelectedButton = new QPushButton( tr( "Save Selected" ) );
77  saveSelectedButton->setDefault(true);
78  buttonsLayout->addWidget( saveSelectedButton );
79  SaveDialogLayout->addLayout( buttonsLayout );
80  languageChange();
81  resize( QSize(500, 300).expandedTo(minimumSizeHint()) );
82  //clearWState( Qt::WA_WState_Polished );
83  setAttribute(Qt::WA_WState_Polished, false);
84 
85  connect(abortClosingButton,SIGNAL(clicked()),this,SLOT(reject()));
86  connect(dontSaveButton,SIGNAL(clicked()),this,SLOT(dontSaveClicked()));
87  connect(saveSelectedButton,SIGNAL(clicked()),this,SLOT(saveSelectedClicked()));
88 }
89 
91 {
92  QString text = (doc->DocName).isEmpty() ? tr("Untitled") : doc->DocName;
93 
94  QListWidgetItem *item = new QListWidgetItem(text, fileView);
95  item->setFlags( item->flags() | Qt::ItemIsUserCheckable );
96  item->setCheckState(Qt::Checked);
97 
98  unsavedDocs.insert(doc, item);
99 }
100 
102 {
103  done(DontSave);
104 }
105 
107 {
108  QList<QucsDoc*> unsavable;
109  QMap<QucsDoc*,QListWidgetItem*>::iterator it(unsavedDocs.begin());
110  for ( ; it != unsavedDocs.end(); ++it)
111  {
112  if ( it.value()->checkState() == Qt::Checked )
113  {
114  QucsDoc *doc = static_cast<QucsDoc*>(it.key());
115  if(app->saveFile(doc) == false)
116  unsavable.append(doc);
117  else
118  unsavedDocs.remove(it);
119  }
120  }
121  if(unsavable.isEmpty())
122  done(SaveSelected);
123 }
124 
126 {
127  done(AbortClosing);
128 }
129 
131 {
132  return unsavedDocs.isEmpty();
133 }
void setApp(QucsApp *a)
Definition: savedialog.cpp:45
QucsApp * app
Definition: savedialog.h:77
bool isEmpty() const
Definition: savedialog.cpp:130
QBoxLayout * SaveDialogLayout
Definition: savedialog.h:74
void saveSelectedClicked()
Definition: savedialog.cpp:106
QLabel * label
Definition: savedialog.h:69
QPushButton * dontSaveButton
Definition: savedialog.h:72
QSpacerItem * spacer
Definition: savedialog.h:76
void dontSaveClicked()
Definition: savedialog.cpp:101
SaveDialog(QWidget *p=0, const char *n=0, bool modal=true, Qt::WFlags fl=0)
Definition: savedialog.cpp:32
QPushButton * abortClosingButton
Definition: savedialog.h:71
bool saveFile(QucsDoc *Doc=0)
Definition: qucs.cpp:1595
QPushButton * saveSelectedButton
Definition: savedialog.h:73
QMap< QucsDoc *, QListWidgetItem * > unsavedDocs
Definition: savedialog.h:67
void addUnsavedDoc(QucsDoc *doc)
Definition: savedialog.cpp:90
QString DocName
Definition: qucsdoc.h:51
void reject()
Definition: savedialog.cpp:125
Definition: qucs.h:61
QListWidget * fileView
Definition: savedialog.h:70
void initDialog()
Definition: savedialog.cpp:50
QHBoxLayout * buttonsLayout
Definition: savedialog.h:75