summaryrefslogtreecommitdiffstats
path: root/kode/kwsdl/kung/pageinputfield.cpp
blob: c5ea0016e1f60a915a70ef64ac320e4e22b443c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
    This file is part of Kung.

    Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <tqlabel.h>
#include <tqlayout.h>

#include "inputfieldfactory.h"

#include "pageinputfield.h"

PageInputField::PageInputField( const TQString &name, const KWSDL::Message &message )
 : InputField( name ),
   mMessage( message )
{
  KWSDL::Message::Part::List parts = message.parts();
  KWSDL::Message::Part::List::ConstIterator it;
  for ( it = parts.begin(); it != parts.end(); ++it ) {
    InputField *field = InputFieldFactory::self()->createField( (*it).name(), (*it).type() );
    if ( !field ) {
      qDebug( "PageInputField: Unable to create input field for %s (%s)", (*it).name().latin1(), (*it).type().latin1() );
    } else {
      appendChild( field );
    }
  }
}

void PageInputField::setXMLData( const TQDomElement &element )
{
  if ( mName != element.tagName() ) {
    qDebug( "PageInputField: Wrong dom element passed: expected %s, got %s", mName.latin1(), element.tagName().latin1() );
    return;
  }

  TQDomNode node = element.firstChild();
  while ( !node.isNull() ) {
    TQDomElement child = node.toElement();
    if ( !child.isNull() ) {
      InputField *field = childField( child.tagName() );
      if ( !field ) {
        qDebug( "PageInputField: Child field %s does not exists", child.tagName().latin1() );
      } else {
        field->setXMLData( child );
      }
    }

    node = node.nextSibling();
  }
}

void PageInputField::xmlData( TQDomDocument &document, TQDomElement &parent )
{
  TQDomElement element = document.createElement( "ns1:" + mName );

  InputField::List::Iterator it;
  for ( it = mFields.begin(); it != mFields.end(); ++it )
    (*it)->xmlData( document, element );

  parent.appendChild( element );
}

void PageInputField::setData( const TQString& )
{
}

TQString PageInputField::data() const
{
  return TQString();
}

TQWidget *PageInputField::createWidget( TQWidget *parent )
{
  TQWidget *mInputWidget = new TQWidget( parent, "PageInputWidget" );
  TQGridLayout *tqlayout = new TQGridLayout( mInputWidget, 2, 2, 11, 6 );

  InputField::List::Iterator it;
  int row = 0;
  for ( it = mFields.begin(); it != mFields.end(); ++it, ++row ) {
    TQLabel *label = new TQLabel( (*it)->name(), mInputWidget );
    label->setAlignment( TQt::AlignTop );
    tqlayout->addWidget( label, row, 0 );
    tqlayout->addWidget( (*it)->createWidget( mInputWidget ), row, 1 );
  }

  tqlayout->setRowStretch( ++row, 1 );

  return mInputWidget;
}

#include "pageinputfield.moc"