//------------------------------------------------------------------------------
void EstimateDetailsForm::populate(const QModelIndex& index)
{
	Estimate* estimate = static_cast<Estimate*>(index.internalPointer());

	// Populate fields with selected estimate's values
	nameField->setText(estimate->estimateName());
	descriptionField->setText(estimate->estimateDescription());
	typeField->setCurrentIndex(typeField->findData(estimate->estimateType()));
	amountField->setValue(estimate->estimatedAmount());
	finishedField->setChecked(estimate->isActivityFinished());

	int offset = estimate->activityDueDateOffset();
	QDate dueDate = period->startDate().addDays(offset);
	if (dueDate.isNull())
	{
		clearDueDate();
	}
	else
	{
		dueDateField->setDate(dueDate);
	}

	// Enable fields that are applicable for all non-root estimates
	nameField->setEnabled(estimate->parentEstimate());
	descriptionField->setEnabled(estimate->parentEstimate());
	// Disable fields that aren't applicable for parents
	amountField->setEnabled(estimate->childCount() == 0);
	dueDateField->setEnabled(estimate->childCount() == 0);
	clearDueDateButton->setEnabled(estimate->childCount() == 0);
	finishedField->setEnabled(estimate->childCount() == 0);

	// Type can only be changed at top-level estimates
	Estimate* parent = estimate->parentEstimate();
	if ( ! parent) // Parent is root
	{
		typeField->setEnabled(false);
	}
	else if ( ! parent->parentEstimate()) // Parent of parent is root
	{
		typeField->setEnabled(true);
	}
	else // Not top-level
	{
		typeField->setEnabled(false);
	}

	// Clear fields that aren't applicable for parents
	if (estimate->childCount() != 0)
	{
		amountField->clear();
		clearDueDate();
		finishedField->setChecked(false);
	}
}
//------------------------------------------------------------------------------
QVariant ImportedTransactionsModel::displayData(const QModelIndex& index) const
{
	int row = index.row();
	if (row < 0 || row >= transactions.size())
		return QVariant();

	ImportedTransaction transaction = transactions.at(row);
	uint id = transaction.transactionId();
	switch (index.column())
	{
	case TRN_ID_COL:
		return id;
	case EST_ID_COL:
		return assignments->estimate(id);
	case RULE_ID_COL:
		return assignments->rule(id);
	case DATE_COL:
		return transaction.date();
	case PAYEE_COL:
		return transaction.payee();
	case MEMO_COL:
		return transaction.memo();
	case AMOUNT_COL:
		return transaction.amount().toString();
	case WITHDRAWAL_COL:
		return transaction.withdrawalAccount();
	case DEPOSIT_COL:
		return transaction.depositAccount();
	case ESTIMATE_COL:
	{
		uint eid = assignments->estimate(id);

		// If transaction was assigned
		if (eid != 0)
		{
			Estimate* estimate = estimates->find(eid);
			if (estimate)
			{
				return estimate->estimateName();
			}
		}

		return QVariant();
	}
	default:
		return QVariant();
	}
}