UASQuickViewItemSelect.cc 2.65 KB
Newer Older
1 2 3 4 5 6 7 8
#include "UASQuickViewItemSelect.h"
#include <QLabel>
#include <QCheckBox>
UASQuickViewItemSelect::UASQuickViewItemSelect(QWidget *parent) : QWidget(parent)
{
    ui.setupUi(this);
    currcol = 0;
    currrow = 0;
9
    ui.gridLayout->setSpacing(5);
10
    ui.gridLayout->setMargin(0);
11 12 13
}
void UASQuickViewItemSelect::addItem(QString item,bool enabled)
{
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    QString category = ".";
    QString name = item;
    if (item.indexOf(":") != -1 && item.indexOf(".") != -1)
    {
        //Item has a subcateogry
        category = item.mid(item.indexOf(":")+1,item.indexOf(".") - item.indexOf(":")-1);
        name = item.mid(item.indexOf(".")+1);
    }
    int col = -1;
    if (m_categoryToIndexMap.contains(category))
    {
        col = m_categoryToIndexMap[category];
    }
    else
    {
        m_categoryToIndexMap[category] = currcol++;
        col = m_categoryToIndexMap[category];
        //New column.
        QLabel *titlelabel = new QLabel(this);
        titlelabel->setText(category);
        titlelabel->show();
        ui.gridLayout->addWidget(titlelabel,0,col);
    }
37
    QCheckBox *label = new QCheckBox(this);
38
    m_checkboxToValueMap[label] = item;
39
    m_checkBoxList.append(label);
40 41 42 43 44
    if (enabled)
    {
        label->setChecked(true);
    }
    connect(label,SIGNAL(clicked(bool)),this,SLOT(checkBoxClicked(bool)));
45
    label->setText(name);
46
    label->show();
47 48 49 50
    //ui.gridLayout->addWidget(label,currrow,currcol++);
    bool breakout = false;
    int row = -1;
    while (!breakout)
51
    {
52 53 54 55
         if (!ui.gridLayout->itemAtPosition(++row,col) || row > 100)
         {
            breakout = true;
         }
56
    }
57 58
    //Row is the next invalid object, and col is the proper column.
    ui.gridLayout->addWidget(label,row,col);
59
}
60 61
void UASQuickViewItemSelect::resizeEvent(QResizeEvent *event)
{
62 63
    Q_UNUSED(event);
    
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    /*for (int i=0;i<m_checkBoxList.size();i++)
    {
        ui.gridLayout->removeWidget(m_checkBoxList[i]);
    }
    int row = 0;
    int col = 0;
    for (int i=0;i<m_checkBoxList.size();i++)
    {
        ui.gridLayout->addWidget(m_checkBoxList[i],row,col);
        col++;
        ui.gridLayout->widget()->width() > this->width();
        //need to reduce column number.

    }*/

}

81 82 83 84 85 86 87
void UASQuickViewItemSelect::checkBoxClicked(bool checked)
{
    QCheckBox *check = qobject_cast<QCheckBox*>(sender());
    if (!check)
    {
        return;
    }
88 89 90 91 92
    QString checkval = check->text();
    if (m_checkboxToValueMap.contains(check))
    {
        checkval = m_checkboxToValueMap[check];
    }
93 94
    if (checked)
    {
95 96

        emit valueEnabled(checkval);
97 98 99
    }
    else
    {
100
        emit valueDisabled(checkval);
101 102 103 104 105 106
    }
}

UASQuickViewItemSelect::~UASQuickViewItemSelect()
{
}