Skip to content

Commit

Permalink
code optimisation, method changeTree + treeLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Rohaut committed Feb 11, 2015
1 parent ac9f78d commit 0a9997d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 72 deletions.
2 changes: 1 addition & 1 deletion documents/LaTexTemplate
2 changes: 1 addition & 1 deletion src/database/customerdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ throw(DbException*)

// Manage any bill/quote of a project of a customer
while (q3.next()) {
QStandardItem *itemBillQuote = new QStandardItem(value(q3,"title").toString()); // Child of child of the item customer
QStandardItem *itemBillQuote = new QStandardItem(value(q3,"date").toString() + " " + value(q3,"title").toString()); // Child of child of the item customer
if (value(q3,"isBilling").toInt() == 0) itemBillQuote->setIcon(QIcon(":icons/img/quote"));
else if (value(q3,"isBilling").toInt() == 1) itemBillQuote->setIcon(QIcon(":icons/img/bill"));
itemProject->appendRow(itemBillQuote);
Expand Down
71 changes: 20 additions & 51 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,63 +301,40 @@ void MainWindow::aboutIcons() {
MessageBox::showAboutIcons();
}

bool MainWindow::isTreeRoot() {
return ui->trCustomers->currentIndex().data() == "Tous les clients";
}

bool MainWindow::isProjectItemTree() {
int i = 0;
QModelIndex currentIndex = ui->trCustomers->currentIndex();
while (currentIndex.parent().isValid()) {
currentIndex = currentIndex.parent();
i++;
}
return i == 1;
}
int MainWindow::treeLevel() {
int ret = 0;

bool MainWindow::isCustomerItemTree() {
return !isTreeRoot() && !ui->trCustomers->currentIndex().parent().isValid();
}

// TODO : difference between bill and quote
bool MainWindow::isQuoteItemTree() {
int i = 0;
QModelIndex currentIndex = ui->trCustomers->currentIndex();
while (currentIndex.parent().isValid()) {
currentIndex = currentIndex.parent();
i++;
}
return i == 2;
}
// TODO : difference between bill and quote
bool MainWindow::isBillItemTree() {
int i = 0;
QModelIndex currentIndex = ui->trCustomers->currentIndex();
while (currentIndex.parent().isValid()) {
currentIndex = currentIndex.parent();
i++;
if (currentIndex.data() != "Tous les clients") {
ret++; // Level = 1, item != root
while (currentIndex.parent().isValid()) {
currentIndex = currentIndex.parent();
ret++;
}
}
return i == 2;
return ret;
}

void MainWindow::changeTree()
{
QModelIndex index = ui->trCustomers->currentIndex();
int idRow = index.row();
//qDebug() << "Change : " << idRow << " " << !isTreeRoot() << " " << ui->trCustomers->currentIndex().parent().parent().isValid();;
if (isTreeRoot()) {
switch (treeLevel()) {
case 0: // Root "Tous les clients"
ui->stackedWidget->setCurrentIndex(0);
ui->tblCustomers->clearSelection();
ui->wdgCustomerData->hide();
ui->trCustomers->collapseAll();
} else if (isCustomerItemTree()) {
break;
case 1: // Customer
ui->tblCustomers->selectRow(idRow-1);
ui->wdgCustomerData->printInformations(getCurrentCustomerId());
ui->trCustomers->collapseAll();
ui->trCustomers->expand(index);
changeProjectsTable();
ui->stackedWidget->setCurrentIndex(1);
} else if (isProjectItemTree()) {
break;
case 2: // Project
// Need to verify if the current customer is the father
// Then update TableProjects
ui->tblCustomers->selectRow(index.parent().row()-1);
Expand All @@ -367,19 +344,8 @@ void MainWindow::changeTree()
//ui->trCustomers->collapseAll();
ui->trCustomers->expand(index);
ui->stackedWidget->setCurrentIndex(2);
} else if (isQuoteItemTree()) {
// TODO
// Need to verify if the current customer is the father
// Need to verify if the current project is the father, also add the
// quote in all fathers where it is referenced
ui->tblCustomers->selectRow(index.parent().parent().row()-1);
updateTableProjects(getCurrentCustomerId());
ui->tblProjects->selectRow(index.parent().row());
updateTableBillings(getCurrentProjectId());
ui->tblQuotes->selectRow(idRow);
ui->stackedWidget->setCurrentIndex(2);
} else if (isBillItemTree()) {
// TODO
break;
case 3: // Bill/Quote
// Need to verify if the current customer is the father
// Need to verify if the current project is the father, also add the
// quote in all fathers where it is referenced
Expand All @@ -389,6 +355,9 @@ void MainWindow::changeTree()
updateTableBillings(getCurrentProjectId());
ui->tblQuotes->selectRow(idRow);
ui->stackedWidget->setCurrentIndex(2);
break;
default: // Other
break;
}

updateBtn();
Expand Down
22 changes: 3 additions & 19 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,11 @@ class MainWindow : public QMainWindow
*/
QString getCurrentProjectName();
/**
* @brief MainWindow::isTreeRoot return if the node selected in the
* tree is the root
* @return boolean
* @brief MainWindow::treeLevel return the level of the node selected in the tree
* @return integer, depth of the item in tree
*/
bool isTreeRoot();
/**
* @brief MainWindow::isCustomerItemTree return if the node selected in the
* tree is a customer
* @return boolean
*/
bool isCustomerItemTree();
/**
* @brief MainWindow::isProjectItemTree return if the node selected in the
* tree is a project
* @return boolean
*/
bool isProjectItemTree();
int treeLevel();

//TODO
bool isQuoteItemTree();
bool isBillItemTree();
void demo();
public slots:
/**
Expand Down

0 comments on commit 0a9997d

Please sign in to comment.