Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Optika_FileNameWidget.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
42 #include <QPushButton>
43 #include <QLabel>
44 #include <QVBoxLayout>
45 #include <QFileDialog>
46 
47 
48 namespace Optika{
49 
50 
51 FileNameWidget::FileNameWidget(QString currentFileName, bool mustAlreadyExist, QWidget *parent)
52  :QWidget(parent),
53  currentFileName(currentFileName),
54  mustAlreadyExist(mustAlreadyExist)
55 {
56  QPushButton *changeButton = new QPushButton("Change Path",this);
57  connect(changeButton, SIGNAL(clicked(bool)), this, SLOT(getNewFileName()));
58  pathLabel = new QLabel(currentFileName,this);
59  QVBoxLayout *layout = new QVBoxLayout(this);
60  layout->addWidget(changeButton);
61  layout->addWidget(pathLabel);
62  setLayout(layout);
63 }
64 
66  return currentFileName;
67 }
68 
69 void FileNameWidget::setCurrentFileName(QString newName){
70  currentFileName = newName;
71  pathLabel->setText(newName);
72 }
73 
75  QString defaultPath;
76  if(currentFileName == ""){
77  defaultPath = QDir::homePath();
78  }
79  else{
80  defaultPath = currentFileName;
81  }
82  if(mustAlreadyExist){
83  QString newFileName = QFileDialog::getOpenFileName(this, tr("File"), defaultPath);
84  if(!newFileName.isNull()){
85  setCurrentFileName(newFileName);
86  }
87  }
88  else{
89  QString newFileName = QFileDialog::getSaveFileName(this, tr("File"), defaultPath);
90  if(!newFileName.isNull()){
91  setCurrentFileName(newFileName);
92  }
93  }
94 }
95 
96 
97 }
98 
bool mustAlreadyExist
Whether or not the file name specified must already exist.
FileNameWidget(QString currentFileName=QString(), bool mustAlreadyExist=false, QWidget *parent=0)
Constructs a FileNameWidget.
void getNewFileName()
Opens a QFileDialog allowing the user to select a new filename.
void setCurrentFileName(QString newName)
Sets the current filename in the widget.
QLabel * pathLabel
The label describing the file path.
QString currentFileName
The current file name stored in the list.
QString getCurrentFileName()
Gets the current filename in the widget.
A widget used to obtain file information in Optika.