Signals | Public Member Functions | Protected Slots | Protected Attributes

QmitkFileChooser Class Reference

Widget showing a line edit with the path of a file or directory and a button which invokes a file choose dialog. More...

#include <QmitkFileChooser.h>

List of all members.

Signals

void NewFileSelected (const std::string &)

Public Member Functions

 QmitkFileChooser (bool horizontalLayout=false, bool selectDir=false, bool fileMustExist=true, QWidget *parent=0, Qt::WindowFlags f=0)
void SetHorizotalLayout (bool horizontalLayout)
void SetSelectDir (bool selectDir)
void SetFileMustExist (bool fileMustExist)
void SetFile (const std::string &file)
void SetFilePattern (const std::string &filepattern)
bool IsValidFile () const
virtual std::string GetFile () const

Protected Slots

virtual void OnSelectFileClicked (bool)

Protected Attributes

bool m_SelectDir
bool m_FileMustExist
bool m_ValidFile
QString m_FilePattern
QPushButton * m_SelectFile
QLineEdit * m_File

Detailed Description

Widget showing a line edit with the path of a file or directory and a button which invokes a file choose dialog.

Definition at line 31 of file QmitkFileChooser.h.


Constructor & Destructor Documentation

QmitkFileChooser::QmitkFileChooser ( bool  horizontalLayout = false,
bool  selectDir = false,
bool  fileMustExist = true,
QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
) [explicit]

Definition at line 27 of file QmitkFileChooser.cpp.

References m_File, m_SelectFile, OnSelectFileClicked(), and SetHorizotalLayout().

: QWidget( parent, f )
, m_SelectDir( selectDir )
, m_FileMustExist(fileMustExist)
{
  m_File = new QLineEdit;
  m_File->setReadOnly( true );
  m_SelectFile = new QPushButton("Select File");
  connect( m_SelectFile, SIGNAL(clicked(bool)), this, SLOT( OnSelectFileClicked( bool ) ) );

  this->SetHorizotalLayout(horizontalLayout);
}

Member Function Documentation

std::string QmitkFileChooser::GetFile (  ) const [virtual]

Definition at line 82 of file QmitkFileChooser.cpp.

References m_File.

{
  return m_File->text().toStdString();
}
bool QmitkFileChooser::IsValidFile (  ) const

Definition at line 77 of file QmitkFileChooser.cpp.

References m_ValidFile.

{
  return m_ValidFile;
}
void QmitkFileChooser::NewFileSelected ( const std::string &   ) [signal]

Referenced by OnSelectFileClicked().

void QmitkFileChooser::OnSelectFileClicked ( bool   ) [protected, virtual, slot]

Definition at line 87 of file QmitkFileChooser.cpp.

References m_File, m_FileMustExist, m_FilePattern, m_SelectDir, and NewFileSelected().

Referenced by QmitkFileChooser().

{

  QString filename;
  if( m_SelectDir )
    filename = QFileDialog::getExistingDirectory( QApplication::activeWindow()
      , "Open directory", m_File->text() );
  else
  {
    if (m_FileMustExist)
      filename = QFileDialog::getOpenFileName( QApplication::activeWindow()
        , "Open file", m_File->text(), m_FilePattern );
    else
      filename = QFileDialog::getSaveFileName( QApplication::activeWindow()
        , "Open file", m_File->text(), m_FilePattern );
  }

  if(!filename.isEmpty())
    m_File->setText( filename );

  emit NewFileSelected(filename.toStdString());
}
void QmitkFileChooser::SetFile ( const std::string &  file )

Definition at line 67 of file QmitkFileChooser.cpp.

References m_File.

{
  m_File->setText( QString::fromStdString(file) );
}
void QmitkFileChooser::SetFileMustExist ( bool  fileMustExist )

Definition at line 62 of file QmitkFileChooser.cpp.

References m_FileMustExist.

{
  m_FileMustExist = fileMustExist;
}
void QmitkFileChooser::SetFilePattern ( const std::string &  filepattern )

Definition at line 72 of file QmitkFileChooser.cpp.

References m_FilePattern.

{
  m_FilePattern = QString::fromStdString(filepattern);
}
void QmitkFileChooser::SetHorizotalLayout ( bool  horizontalLayout )

Definition at line 42 of file QmitkFileChooser.cpp.

References m_File, and m_SelectFile.

Referenced by QmitkFileChooser().

{
  QBoxLayout* layout = 0;
  if(horizontalLayout)
    layout = new QHBoxLayout;
   else
    layout = new QVBoxLayout;

  layout->setContentsMargins(0,0,0,0);
  layout->addWidget( m_File );
  layout->addWidget( m_SelectFile );

  this->setLayout( layout );
}
void QmitkFileChooser::SetSelectDir ( bool  selectDir )

Definition at line 57 of file QmitkFileChooser.cpp.

References m_SelectDir.

{
  m_SelectDir = selectDir;
}

Member Data Documentation

QLineEdit* QmitkFileChooser::m_File [protected]

Definition at line 59 of file QmitkFileChooser.h.

Referenced by OnSelectFileClicked(), and SetFileMustExist().

QString QmitkFileChooser::m_FilePattern [protected]

Definition at line 62 of file QmitkFileChooser.h.

Referenced by OnSelectFileClicked(), and SetFilePattern().

Definition at line 58 of file QmitkFileChooser.h.

Referenced by OnSelectFileClicked(), and SetSelectDir().

QPushButton* QmitkFileChooser::m_SelectFile [protected]

Definition at line 63 of file QmitkFileChooser.h.

Referenced by QmitkFileChooser(), and SetHorizotalLayout().

Definition at line 60 of file QmitkFileChooser.h.

Referenced by IsValidFile().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines