Commit 092d8ca9 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Restored changes to the overview combo that accidentally got reverted

Accidentally reverted in commit 713105ad.
Thanks to Christian Hönig for notifying.
parent 4e1025fb
......@@ -75,6 +75,7 @@
#include <QtGui/QTextEdit>
#include <QtGui/QComboBox>
#include <QtGui/QTreeView>
#include <QtGui/QSortFilterProxyModel>
using namespace CPlusPlus;
using namespace CppEditor::Internal;
......@@ -243,7 +244,22 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
m_methodCombo->setMaxVisibleItems(20);
m_overviewModel = new OverviewModel(this);
m_methodCombo->setModel(m_overviewModel);
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_overviewModel);
if (CppPlugin::instance()->sortedMethodOverview())
m_proxyModel->sort(0, Qt::AscendingOrder);
else
m_proxyModel->sort(-1, Qt::AscendingOrder); // don't sort yet, but set column for sortedMethodOverview()
m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_methodCombo->setModel(m_proxyModel);
m_methodCombo->setContextMenuPolicy(Qt::ActionsContextMenu);
m_sortAction = new QAction(tr("Sort alphabetically"), m_methodCombo);
m_sortAction->setCheckable(true);
m_sortAction->setChecked(sortedMethodOverview());
connect(m_sortAction, SIGNAL(toggled(bool)), CppPlugin::instance(), SLOT(setSortedMethodOverview(bool)));
m_methodCombo->addAction(m_sortAction);
connect(m_methodCombo, SIGNAL(activated(int)), this, SLOT(jumpToMethod(int)));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateMethodBoxIndex()));
......@@ -366,7 +382,7 @@ void CPPEditor::updateFileName()
void CPPEditor::jumpToMethod(int)
{
QModelIndex index = m_methodCombo->view()->currentIndex();
QModelIndex index = m_proxyModel->mapToSource(m_methodCombo->view()->currentIndex());
Symbol *symbol = m_overviewModel->symbolFromIndex(index);
if (! symbol)
return;
......@@ -374,6 +390,25 @@ void CPPEditor::jumpToMethod(int)
openCppEditorAt(linkToSymbol(symbol));
}
void CPPEditor::setSortedMethodOverview(bool sort)
{
if (sort != sortedMethodOverview()) {
if (sort)
m_proxyModel->sort(0, Qt::AscendingOrder);
else
m_proxyModel->sort(-1, Qt::AscendingOrder);
bool block = m_sortAction->blockSignals(true);
m_sortAction->setChecked(m_proxyModel->sortColumn() == 0);
m_sortAction->blockSignals(block);
updateMethodBoxIndex();
}
}
bool CPPEditor::sortedMethodOverview() const
{
return (m_proxyModel->sortColumn() == 0);
}
void CPPEditor::updateMethodBoxIndex()
{
int line = 0, column = 0;
......@@ -394,7 +429,7 @@ void CPPEditor::updateMethodBoxIndex()
if (lastIndex.isValid()) {
bool blocked = m_methodCombo->blockSignals(true);
m_methodCombo->setCurrentIndex(lastIndex.row());
m_methodCombo->setCurrentIndex(m_proxyModel->mapFromSource(lastIndex).row());
updateMethodBoxToolTip();
(void) m_methodCombo->blockSignals(blocked);
}
......
......@@ -37,6 +37,7 @@
QT_BEGIN_NAMESPACE
class QComboBox;
class QSortFilterProxyModel;
QT_END_NAMESPACE
namespace CPlusPlus {
......@@ -86,6 +87,7 @@ public:
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
void setSortedMethodOverview(bool sort);
void switchDeclarationDefinition();
void jumpToDefinition();
......@@ -94,7 +96,6 @@ public slots:
void deleteStartOfToken();
void deleteEndOfToken();
protected:
void contextMenuEvent(QContextMenuEvent *);
void mouseMoveEvent(QMouseEvent *);
......@@ -115,6 +116,7 @@ private slots:
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
private:
bool sortedMethodOverview() const;
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol);
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
......@@ -161,6 +163,8 @@ private:
QList<int> m_contexts;
QComboBox *m_methodCombo;
CPlusPlus::OverviewModel *m_overviewModel;
QSortFilterProxyModel *m_proxyModel;
QAction *m_sortAction;
};
} // namespace Internal
......
......@@ -106,7 +106,8 @@ CppPlugin *CppPlugin::m_instance = 0;
CppPlugin::CppPlugin() :
m_actionHandler(0),
m_factory(0)
m_factory(0),
m_sortedMethodOverview(false)
{
m_instance = this;
}
......@@ -133,6 +134,20 @@ void CppPlugin::initializeEditor(CPPEditor *editor)
// auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool)));
// method combo box sorting
connect(this, SIGNAL(methodOverviewSortingChanged(bool)),
editor, SLOT(setSortedMethodOverview(bool)));
}
void CppPlugin::setSortedMethodOverview(bool sorted)
{
m_sortedMethodOverview = sorted;
emit methodOverviewSortingChanged(sorted);
}
bool CppPlugin::sortedMethodOverview() const
{
return m_sortedMethodOverview;
}
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
......@@ -194,14 +209,30 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll);
readSettings();
return true;
}
void CppPlugin::readSettings()
{
m_sortedMethodOverview = Core::ICore::instance()->settings()->value("CppTools/SortedMethodOverview", false).toBool();
}
void CppPlugin::writeSettings()
{
Core::ICore::instance()->settings()->setValue("CppTools/SortedMethodOverview", m_sortedMethodOverview);
}
void CppPlugin::extensionsInitialized()
{
m_actionHandler->initializeActions();
}
void CppPlugin::shutdown()
{
writeSettings();
}
void CppPlugin::switchDeclarationDefinition()
{
Core::EditorManager *em = Core::EditorManager::instance();
......
......@@ -58,10 +58,19 @@ public:
bool initialize(const QStringList &arguments, QString *error_message = 0);
void extensionsInitialized();
void shutdown();
// Connect editor to settings changed signals.
void initializeEditor(CPPEditor *editor);
bool sortedMethodOverview() const;
signals:
void methodOverviewSortingChanged(bool sort);
public slots:
void setSortedMethodOverview(bool sorted);
private slots:
void switchDeclarationDefinition();
void jumpToDefinition();
......@@ -69,11 +78,14 @@ private slots:
private:
friend class CppEditorFactory;
Core::IEditor *createEditor(QWidget *parent);
void writeSettings();
void readSettings();
static CppPlugin *m_instance;
TextEditor::TextEditorActionHandler *m_actionHandler;
CppEditorFactory *m_factory;
bool m_sortedMethodOverview;
};
class CppEditorFactory : public Core::IEditorFactory
......
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