Commit be9dfc8c authored by con's avatar con

Fixes: - Show <No Symbols> or <Select Symbol> in 'empty' method combo box

Task:     - 234321
RevBy:    - Bjoern
parent b220999b
......@@ -74,10 +74,10 @@ Symbol *OverviewModel::globalSymbolAt(unsigned index) const
QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent) const
{
if (! hasDocument()) {
return QModelIndex();
} else if (! parent.isValid()) {
Symbol *symbol = globalSymbolAt(row);
if (!parent.isValid()) {
if (row == 0) // account for no symbol item
return createIndex(row, column);
Symbol *symbol = globalSymbolAt(row-1); // account for no symbol item
return createIndex(row, column, symbol);
} else {
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
......@@ -96,12 +96,20 @@ QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent)
QModelIndex OverviewModel::parent(const QModelIndex &child) const
{
Symbol *symbol = static_cast<Symbol *>(child.internalPointer());
Q_ASSERT(symbol != 0);
if (!symbol) // account for no symbol item
return QModelIndex();
if (Scope *scope = symbol->scope()) {
Symbol *parentSymbol = scope->owner();
if (parentSymbol && parentSymbol->scope())
return createIndex(parentSymbol->index(), 0, parentSymbol);
if (parentSymbol && parentSymbol->scope()) {
QModelIndex index;
if (parentSymbol->scope() && parentSymbol->scope()->owner()
&& parentSymbol->scope()->owner()->scope()) // the parent doesn't have a parent
index = createIndex(parentSymbol->index(), 0, parentSymbol);
else //+1 to account for no symbol item
index = createIndex(parentSymbol->index() + 1, 0, parentSymbol);
return index;
}
}
return QModelIndex();
......@@ -110,22 +118,27 @@ QModelIndex OverviewModel::parent(const QModelIndex &child) const
int OverviewModel::rowCount(const QModelIndex &parent) const
{
if (hasDocument()) {
if (! parent.isValid()) {
return globalSymbolCount();
if (!parent.isValid()) {
return globalSymbolCount()+1; // account for no symbol item
} else {
if (!parent.parent().isValid() && parent.row() == 0) // account for no symbol item
return 0;
Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer());
Q_ASSERT(parentSymbol != 0);
if (ScopedSymbol *scopedSymbol = parentSymbol->asScopedSymbol()) {
if (! scopedSymbol->isFunction()) {
if (!scopedSymbol->isFunction()) {
Scope *parentScope = scopedSymbol->members();
Q_ASSERT(parentScope != 0);
return parentScope->symbolCount();
}
}
return 0;
}
}
if (!parent.isValid())
return 1; // account for no symbol item
return 0;
}
......@@ -136,6 +149,19 @@ int OverviewModel::columnCount(const QModelIndex &) const
QVariant OverviewModel::data(const QModelIndex &index, int role) const
{
// account for no symbol item
if (!index.parent().isValid() && index.row() == 0) {
switch (role) {
case Qt::DisplayRole:
if (rowCount() > 1)
return tr("<Select Symbol>");
else
return tr("<No Symbols>");
default:
return QVariant();
} //switch
}
switch (role) {
case Qt::DisplayRole: {
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
......
......@@ -203,9 +203,7 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
m_methodCombo->setMaxVisibleItems(20);
m_overviewModel = new OverviewModel(this);
m_noSymbolsModel = new QStringListModel(this);
m_noSymbolsModel->setStringList(QStringList() << tr("<no symbols>"));
m_methodCombo->setModel(m_noSymbolsModel);
m_methodCombo->setModel(m_overviewModel);
connect(m_methodCombo, SIGNAL(activated(int)), this, SLOT(jumpToMethod(int)));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateMethodBoxIndex()));
......@@ -318,16 +316,9 @@ void CPPEditor::onDocumentUpdated(Document::Ptr doc)
return;
m_overviewModel->rebuild(doc);
if (m_overviewModel->rowCount() > 0) {
if (m_methodCombo->model() != m_overviewModel)
m_methodCombo->setModel(m_overviewModel);
OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view());
treeView->sync();
updateMethodBoxIndex();
} else {
if (m_methodCombo->model() != m_noSymbolsModel)
m_methodCombo->setModel(m_noSymbolsModel);
}
OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view());
treeView->sync();
updateMethodBoxIndex();
}
void CPPEditor::updateFileName()
......@@ -335,8 +326,6 @@ void CPPEditor::updateFileName()
void CPPEditor::jumpToMethod(int)
{
if (m_methodCombo->model() != m_overviewModel)
return;
QModelIndex index = m_methodCombo->view()->currentIndex();
Symbol *symbol = m_overviewModel->symbolFromIndex(index);
if (! symbol)
......@@ -351,8 +340,6 @@ void CPPEditor::jumpToMethod(int)
void CPPEditor::updateMethodBoxIndex()
{
if (m_methodCombo->model() != m_overviewModel)
return;
int line = 0, column = 0;
convertPosition(position(), &line, &column);
......@@ -362,7 +349,7 @@ void CPPEditor::updateMethodBoxIndex()
for (int row = 0; row < rc; ++row) {
const QModelIndex index = m_overviewModel->index(row, 0, QModelIndex());
Symbol *symbol = m_overviewModel->symbolFromIndex(index);
if (symbol->line() > unsigned(line))
if (symbol && symbol->line() > unsigned(line))
break;
lastIndex = index;
}
......
......@@ -139,7 +139,6 @@ private:
QList<int> m_contexts;
QComboBox *m_methodCombo;
CPlusPlus::OverviewModel *m_overviewModel;
QStringListModel *m_noSymbolsModel;
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment