Skip to content

Commit

Permalink
Stashing to switch tickets
Browse files Browse the repository at this point in the history
Now creating the functionality to populate the tree.
Committing in order to switch branches and fix a reopened ticket

Refs #3737
  • Loading branch information
keithnbrown committed Jul 22, 2013
1 parent 1bdfcc7 commit fc16513
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 3 deletions.
Expand Up @@ -109,6 +109,10 @@ private slots:
void populateTree (const std::string &workspace);
/// Recursivly parses teh supplied equaison inot a
int parseEquation(QString* eq);
/// add entries to the map and return the calling function's data id
int addToBinaryTreeMap(QString l, QString data, QString r);
/// use the key to get the values from the map to create the shapes and add to the tree recursively
void addToQTreeWidget(QString k);
private:
/// The form generated with Qt Designer
Ui::CreateSampleShapeDialog m_uiForm;
Expand All @@ -128,6 +132,8 @@ private slots:
Poco::XML::Element* m_pRootElem;
/// Map holding the layout of the tree ready for construction.
QHash<QString,QVector<QString>> m_binaryTreeMap;
/// integer makrer for the layout fo the tree, to be incremented after each new addition to the map
int m_mapID;
};

/**
Expand Down
141 changes: 138 additions & 3 deletions Code/Mantid/MantidQt/CustomDialogs/src/CreateSampleShapeDialog.cpp
Expand Up @@ -210,10 +210,108 @@ void CreateSampleShapeDialog::populateTree(const std::string &workspace)
throw std::runtime_error("No shape algebra definition");
}

//int rootTreeNodeKey = parseEquation(&equation);
int rootTreeNodeKey = parseEquation(&equation);

}
}
void CreateSampleShapeDialog::addToQTreeWidget(QString k, const BinaryTreeWidgetItem* parent)
{
m_binaryTreeMap[k];
BinaryTreeWidgetItem *child = new BinaryTreeWidgetItem();
QFont font = child->font(0);
font.setBold(true);
operation->setFont(0, font);
operation->setData(0, Qt::DisplayRole, opt->text());
//Shape code

/*
// Get the selected item
BinaryTreeWidgetItem *parent = getSelectedItem();
if( parent && parent->childCount() == 2 ) return;
BinaryTreeWidgetItem *child = new BinaryTreeWidgetItem(QStringList(shape->text()));
child->setFlags(child->flags() & ~Qt::ItemIsEditable);
if( m_shapeTree->topLevelItemCount() == 0 )
{
m_shapeTree->insertTopLevelItem(0, child);
}
else
{
parent->addChildItem(child);
}
// This calls setupDetails
m_shapeTree->setCurrentItem(child);
m_shapeTree->expandAll();
*/


// operator code
/*
//Get the selected item
BinaryTreeWidgetItem *selected = getSelectedItem();
if( selected && selected->childCount() == 2 ) return;
BinaryTreeWidgetItem *operation = new BinaryTreeWidgetItem;
QFont font = operation->font(0);
font.setBold(true);
operation->setFont(0, font);
operation->setData(0, Qt::DisplayRole, opt->text());
int opcode(0);
if( opt->text().startsWith("u") ) opcode = 1;
else if( opt->text().startsWith("d") ) opcode = 2;
else opcode = 0;
operation->setData(0, Qt::UserRole, opcode);
operation->setFlags(operation->flags() | Qt::ItemIsEditable);
if( m_shapeTree->topLevelItemCount() == 0 )
{
m_shapeTree->insertTopLevelItem(0, operation);
}
else
{
if( m_ops_map.contains(selected) )
{
selected->addChildItem(operation);
}
else if( selected->parent() )
{
int index = selected->parent()->indexOfChild(selected);
selected->parent()->insertChild(index, operation);
selected->parent()->removeChild(selected);
operation->addChildItem(selected);
}
else
{
m_shapeTree->takeTopLevelItem(m_shapeTree->indexOfTopLevelItem(selected));
m_shapeTree->insertTopLevelItem(0, operation);
operation->addChildItem(selected);
}
}
m_ops_map.insert(operation, new Operation(opcode));
// This calls setupDetails if necessary
m_shapeTree->setCurrentItem(operation);
m_shapeTree->expandAll();
*/
}

int CreateSampleShapeDialog::addToBinaryTreeMap(QString l, QString data, QString r)
{
//add the info to the vector in the format [0] = L, [1] = shape/operation, [2] = R
//then add that to the map
QVector<QString> val;
val.push_back(l);
val.push_back(data);
val.push_back(r);
int mID = m_mapID++;
m_binaryTreeMap[QString::number(mID)] = val;
return mID;
}

int CreateSampleShapeDialog::parseEquation(QString* eq)
{
Expand All @@ -227,9 +325,9 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
//strip out any stray parentheses
eq->remove(QChar('('));
eq->remove(QChar(')'));

//add the info to the vector in the format [0] = L, [1] = shape/operation, [2] = R
//then add that to the map
return addToBinaryTreeMap("", *eq, "");
}
else if (operations == 1)
{
Expand All @@ -244,6 +342,18 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
int rightInd = parseEquation(&eqR);
//add the info to the vector in the format [0] = L, [1] = shape/operation, [2] = R
//then add that to the map
if (eq->at(opPos) == QChar(' '))
{
return addToBinaryTreeMap(QString::number(leftInd), " ", QString::number(rightInd));
}
else if (eq->at(opPos) == QChar(':'))
{
return addToBinaryTreeMap(QString::number(leftInd), ":", QString::number(rightInd));
}
else
{
throw std::runtime_error("Problem determining operation");
}
}
else
{
Expand All @@ -255,7 +365,7 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
int closeBrackets = eq->count(QChar(')'));
if (openBrackets == 0 || closeBrackets == 0)
{
//if there aren't any brackets of one type or another resolve the opperations left to right
//if there aren't any brackets of one type or another, resolve the opperations left to right
//this isn't really well formatted but i'll parse it anyway
QString eqL;
QString eqR;
Expand All @@ -267,6 +377,18 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
int rightInd = parseEquation(&eqR);
//add the info to the vector in the format [0] = L, [1] = shape/operation, [2] = R
//then add that to the map
if (eq->at(opPos) == QChar(' '))
{
return addToBinaryTreeMap(QString::number(leftInd), " ", QString::number(rightInd));
}
else if (eq->at(opPos) == QChar(':'))
{
return addToBinaryTreeMap(QString::number(leftInd), ":", QString::number(rightInd));
}
else
{
throw std::runtime_error("Problem determining operation");
}
}
else if (openBrackets > closeBrackets)
{
Expand Down Expand Up @@ -352,6 +474,18 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
int rightInd = parseEquation(&eqR);
//add the info to the vector in the format [0] = L, [1] = shape/operation, [2] = R
//then add that to the map
if (eq->at(i) == QChar(' '))
{
return addToBinaryTreeMap(QString::number(leftInd), " ", QString::number(rightInd));
}
else if (eq->at(i) == QChar(':'))
{
return addToBinaryTreeMap(QString::number(leftInd), ":", QString::number(rightInd));
}
else
{
throw std::runtime_error("Problem determining operation");
}
}
else
{
Expand All @@ -360,6 +494,7 @@ int CreateSampleShapeDialog::parseEquation(QString* eq)
}
}
}
throw std::runtime_error("Shape algebra definition not properly formatted");
}

/**
Expand Down

0 comments on commit fc16513

Please sign in to comment.