attributedialog.cpp
author insilmaril
Wed, 05 Dec 2007 14:58:03 +0000
changeset 630 4998bb082c73
parent 626 96c8e6860e0c
child 637 0ff5fc89dc5c
permissions -rw-r--r--
Added files from Andrew Ng for Windows
insilmaril@623
     1
#include "attributedialog.h"
insilmaril@623
     2
insilmaril@626
     3
#include "attributewidget.h"
insilmaril@626
     4
insilmaril@626
     5
#include <QtGui/QApplication>
insilmaril@626
     6
#include <QtGui/QButtonGroup>
insilmaril@623
     7
insilmaril@623
     8
AttributeDialog::AttributeDialog (QWidget *parent):QDialog (parent)
insilmaril@623
     9
{
insilmaril@626
    10
    if (this->objectName().isEmpty())
insilmaril@626
    11
        this->setObjectName(QString::fromUtf8("AttributeDialog"));
insilmaril@626
    12
    QSize size(468, 75);
insilmaril@626
    13
    size = size.expandedTo(this->minimumSizeHint());
insilmaril@626
    14
    this->resize(size);
insilmaril@626
    15
    QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
insilmaril@626
    16
    sizePolicy.setHorizontalStretch(0);
insilmaril@626
    17
    sizePolicy.setVerticalStretch(0);
insilmaril@626
    18
    sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
insilmaril@626
    19
    this->setSizePolicy(sizePolicy);
insilmaril@626
    20
insilmaril@626
    21
    vboxLayout = new QVBoxLayout(this);
insilmaril@626
    22
    vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
insilmaril@626
    23
insilmaril@626
    24
    tableLayout = new QVBoxLayout();
insilmaril@626
    25
    tableLayout->setObjectName(QString::fromUtf8("tableLayout"));
insilmaril@626
    26
insilmaril@626
    27
    hboxLayout = new QHBoxLayout();
insilmaril@626
    28
    hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
insilmaril@626
    29
    addButton = new QPushButton(this);
insilmaril@626
    30
    addButton->setObjectName(QString::fromUtf8("addButton"));
insilmaril@626
    31
insilmaril@626
    32
    hboxLayout->addWidget(addButton);
insilmaril@626
    33
insilmaril@626
    34
    spacerItem = new QSpacerItem(111, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
insilmaril@626
    35
insilmaril@626
    36
    hboxLayout->addItem(spacerItem);
insilmaril@626
    37
insilmaril@626
    38
    closeButton = new QPushButton(this);
insilmaril@626
    39
    closeButton->setObjectName(QString::fromUtf8("closeButton"));
insilmaril@626
    40
insilmaril@626
    41
    hboxLayout->addWidget(closeButton);
insilmaril@626
    42
insilmaril@626
    43
    vboxLayout->addLayout(tableLayout);
insilmaril@626
    44
    vboxLayout->addLayout(hboxLayout);
insilmaril@626
    45
insilmaril@626
    46
insilmaril@626
    47
	
insilmaril@626
    48
    setWindowTitle(QApplication::translate("AttributeDialog", "Attributes", 0, QApplication::UnicodeUTF8));
insilmaril@626
    49
    addButton->setText(QApplication::translate("AttributeDialog", "Add key", 0, QApplication::UnicodeUTF8));
insilmaril@626
    50
    closeButton->setText(QApplication::translate("AttributeDialog", "Close", 0, QApplication::UnicodeUTF8));
insilmaril@626
    51
insilmaril@626
    52
	connect (addButton, SIGNAL (clicked()), this, SLOT (addKey()));
insilmaril@626
    53
	connect (closeButton, SIGNAL (clicked()), this, SLOT (accept()));
insilmaril@626
    54
insilmaril@626
    55
	table=NULL;
insilmaril@623
    56
}
insilmaril@623
    57
insilmaril@626
    58
void AttributeDialog::setTable (AttributeTable *t)
insilmaril@626
    59
{
insilmaril@626
    60
	table=t;
insilmaril@626
    61
	updateTable();
insilmaril@626
    62
}
insilmaril@626
    63
insilmaril@626
    64
void AttributeDialog::setBranch (BranchObj *bo)
insilmaril@626
    65
{
insilmaril@626
    66
	branch=bo;
insilmaril@626
    67
	updateTable();
insilmaril@626
    68
}
insilmaril@626
    69
insilmaril@626
    70
void AttributeDialog::addKey()
insilmaril@626
    71
{
insilmaril@626
    72
	AttributeWidget *aw1=new AttributeWidget (this);
insilmaril@626
    73
	aw1->show();
insilmaril@626
    74
	tableLayout->addWidget (aw1);
insilmaril@626
    75
insilmaril@626
    76
}
insilmaril@623
    77
insilmaril@623
    78
void AttributeDialog::closeEvent( QCloseEvent* ce )
insilmaril@623
    79
{
insilmaril@623
    80
    ce->accept();	// can be reopened with show()
insilmaril@623
    81
	hide();
insilmaril@623
    82
	emit (windowClosed() );
insilmaril@623
    83
    return;
insilmaril@623
    84
}
insilmaril@623
    85
insilmaril@626
    86
void AttributeDialog::updateTable()
insilmaril@626
    87
{
insilmaril@626
    88
	if (table)
insilmaril@626
    89
	{
insilmaril@626
    90
		// Update list of keys and values
insilmaril@626
    91
		QStringList keyList=table->getKeys();
insilmaril@626
    92
		AttributeWidget *aw;
insilmaril@626
    93
		int i;
insilmaril@626
    94
		for (i=0; i<keyList.count();i++)
insilmaril@626
    95
		{
insilmaril@626
    96
			aw=new AttributeWidget (this);
insilmaril@626
    97
			aw->setKey (keyList.at(i) );
insilmaril@626
    98
			aw->setValues (table->getValues (keyList.at(i) ));
insilmaril@626
    99
			aw->show();
insilmaril@626
   100
			tableLayout->addWidget (aw);
insilmaril@626
   101
		}
insilmaril@623
   102
insilmaril@626
   103
		// Update attributes in dialog from data in selected branch
insilmaril@623
   104
insilmaril@626
   105
		// TODO
insilmaril@626
   106
	}
insilmaril@626
   107
insilmaril@626
   108
}
insilmaril@626
   109