kandy Library API Documentation

cmdpropertiesdialog.cpp

00001 // $Id: cmdpropertiesdialog.cpp,v 1.2 2001/09/14 06:57:29 mlaurent Exp $
00002 
00003 #include <qlistview.h>
00004 #include <qlineedit.h>
00005 #include <qcheckbox.h>
00006 
00007 #include <klineeditdlg.h>
00008 #include <klocale.h>
00009 
00010 #include "atcommand.h"
00011 
00012 #include "cmdpropertiesdialog.h"
00013 #include "cmdpropertiesdialog.moc"
00014 
00015 class ParameterItem : public QCheckListItem {
00016   public:
00017     ParameterItem(ATParameter *p,QListView *parent) :
00018         QCheckListItem(parent,p->name(),CheckBox),mParameter(p)
00019     {
00020       setText(1,p->value());
00021       setOn(p->userInput());
00022     }
00023         
00024     void writeParameter()
00025     {
00026       mParameter->setName(text(0));
00027       mParameter->setValue(text(1));
00028       mParameter->setUserInput(isOn());
00029     }
00030     
00031   private:
00032     ATParameter *mParameter;
00033 };
00034 
00035 
00036 /* 
00037  *  Constructs a CmdPropertiesDialog which is a child of 'parent', with the 
00038  *  name 'name' and widget flags set to 'f' 
00039  *
00040  *  The dialog will by default be modeless, unless you set 'modal' to
00041  *  TRUE to construct a modal dialog.
00042  */
00043 CmdPropertiesDialog::CmdPropertiesDialog(ATCommand *cmd, QWidget* parent,
00044                                          const char* name, bool modal,
00045                                          WFlags fl )
00046     : CmdPropertiesDialog_base( parent, name, modal, fl )
00047 {
00048   mCmd = cmd;
00049   
00050   readCommand();
00051 }
00052 
00053 CmdPropertiesDialog::~CmdPropertiesDialog()
00054 {
00055 }
00056 
00057 void CmdPropertiesDialog::readCommand()
00058 {
00059   mNameEdit->setText(mCmd->cmdName());
00060   mStringEdit->setText(mCmd->cmdString());
00061   mHexCheck->setChecked(mCmd->hexOutput());
00062 
00063   QPtrList<ATParameter> parameters = mCmd->parameters();
00064   for(int i=(int)parameters.count()-1;i>=0;--i) {
00065     ATParameter *p = parameters.at(i);
00066     new ParameterItem(p,mParameterList);
00067   }
00068 }
00069 
00070 void CmdPropertiesDialog::writeCommand()
00071 {
00072   mCmd->setCmdName(mNameEdit->text());
00073   mCmd->setCmdString(mStringEdit->text());
00074   mCmd->setHexOutput(mHexCheck->isChecked());
00075   ParameterItem *item = (ParameterItem *)mParameterList->firstChild();
00076   while (item) {
00077     item->writeParameter();
00078     item = (ParameterItem *)item->nextSibling();
00079   }
00080 }
00081 
00082 void CmdPropertiesDialog::editParameterName(QListViewItem *item)
00083 {
00084   bool ok = false;
00085 
00086   QString newName = KLineEditDlg::getText(i18n("Enter parameter name"),
00087                                           item->text(0),&ok,this);
00088 
00089   if (ok) {
00090     item->setText(0,newName);
00091   }
00092 }
00093 
00094 void CmdPropertiesDialog::slotAccept()
00095 {
00096   writeCommand();
00097   accept();
00098 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:06 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001