void frmMainStateTable::setupUI(bool hasRowLabels_)
{
    ui = createUI();
    ui->setupUI(tableColumns(), hasRowLabels_, static_cast<QWidget*>(this->parent()));

    ui->toolbarDateBeginEdit->setDate(QDate::fromJulianDay(m_portfolio.startDate()));
    ui->toolbarDateEndEdit->setDate(QDate::fromJulianDay(m_portfolio.endDate()));
    setSortDropDown();

    connect(ui->toolbarDateBeginEdit, SIGNAL(dateChanged(QDate)), this, SLOT(refreshTab()));
    connect(ui->toolbarDateEndEdit, SIGNAL(dateChanged(QDate)), this, SLOT(refreshTab()));
    connect(ui->toolbarSortCmb, SIGNAL(activated(int)), this, SLOT(sortIndexChanged(int)));
    connect(ui->toolbarReorder, SIGNAL(triggered()), this, SLOT(modifyColumns()));
    connect(ui->toolbarExport, SIGNAL(triggered()), ui->table, SLOT(exportTable()));
    connect(ui->tableCopy, SIGNAL(activated()), ui->table, SLOT(copyTable()));
	connect(ui->toolbar1D, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar3M, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar6M, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbarYTD, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar1Y, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar5Y, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbarMax, SIGNAL(triggered()), this, SLOT(dateClicked()));
    refreshTab();

    connect(ui->table,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(cellSelected(const QModelIndex &)));

}
frmMainChart_State::frmMainChart_State(int portfolioID_, const QMap<int, portfolio> &portfolios_, const QHash<QString, historicalPrices> &prices_, QWidget *parent_):
    frmMainStateToolbar(portfolios_.value(portfolioID_), parent_),
    frmMainStateTree(portfolios_, prices_),
    ui(new frmMainChart_UI()),
    m_counter(0)
{
    ui->setupUI(static_cast<QWidget*>(this->parent()));
    foreach(const portfolio &p, m_portfolios)
       ui->treeCmb->addItem(p.displayText(), p.id());
    ui->treeCmb->setCurrentIndex(ui->treeCmb->findData(m_portfolio.id()));
    populateTree(portfolioID_);

    int beginDate = m_portfolio.startDate();
    int endDate = m_portfolio.endDate();

    ui->toolbarDateBeginEdit->setDate(QDate::fromJulianDay(beginDate));
    ui->toolbarDateEndEdit->setDate(QDate::fromJulianDay(endDate));

    connect(ui->toolbarDateBeginEdit, SIGNAL(dateChanged(QDate)), this, SLOT(refreshTab()));
    connect(ui->toolbarDateEndEdit, SIGNAL(dateChanged(QDate)), this, SLOT(refreshTab()));
    connect(ui->toolbarExport, SIGNAL(triggered()), ui->chart, SLOT(exportChart()));
    connect(ui->tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChecked(QTreeWidgetItem*,int)));
    connect(ui->treeCmb, SIGNAL(currentIndexChanged(int)), SLOT(portfolioChange(int)));
    connect(ui->treeAllPortfolios, SIGNAL(clicked()), this, SLOT(addAllPortfolios()));
    connect(ui->treeClearBtn, SIGNAL(clicked()), this, SLOT(clearTree()));
    connect(ui->toolbar3M, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar6M, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbarYTD, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar1Y, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbar5Y, SIGNAL(triggered()), this, SLOT(dateClicked()));
    connect(ui->toolbarMax, SIGNAL(triggered()), this, SLOT(dateClicked()));

    refreshTab();
}