/***************************************************************************
* Copyright (C) 2007-2009 by Elad Lahav
* elad_lahav@users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
***************************************************************************/
#include <QDebug>
#include <core/exception.h>
#include "lexerstylemodel.h"
#include "config.h"
namespace KScope
{
namespace Editor
{
const QString LexerStyleModel::inheritValue_ = "<Inherit>";
const QString LexerStyleModel::styleMagic_ = "Grqt237gva5FA8A3";
/**
* Class constructor.
* @param parent Parent object
*/
LexerStyleModel::LexerStyleModel(const Config::LexerList& lexers,
QObject* parent)
: QAbstractItemModel(parent), root_(NULL)
{
// Build the style tree from the list of lexers.
// The first object is assumed to be the common defaults lexer.
Node* defNode = NULL;
foreach (QsciLexer* lexer, lexers) {
if (defNode == NULL) {
// Create the root node.
defNode = createStyleNode(&root_, lexer);
}
else {
// Create the default style node for this lexer.
Node* lexNode = createStyleNode(defNode, lexer);
// Create per-style nodes for this lexer.
for (int i = 0; !lexer->description(i).isEmpty(); i++) {
// Skip the default style.
if (i == lexer->defaultStyle())
continue;
createStyleNode(lexNode, lexer, i);
}
}
}
}
/**
* Class destructor.
*/
LexerStyleModel::~LexerStyleModel()
{
deleteStyleNode(root_.child(0));
}
/**
* Reads style data from a QSettings object
* @param settings The object to read from
* @param force Trust the given settings file, and try to load styles even
* if the magic key is not found
* @throw Exception If force is not set, thrown in case the magic key is not
* found
*/
void LexerStyleModel::load(QSettings& settings, bool force)
{
// Check for a magic key, identifying the settings object as a valid style
// scheme.
settings.beginGroup("EditorStyles");
if (!force) {
if ((settings.status() != QSettings::NoError)
|| (settings.value("KScopeStyleSchemeMagic", "").toString()
!= styleMagic_)) {
settings.endGroup();
throw new Core::Exception(tr("Not a valid style scheme"));
}
}
// Recursively load styles.
loadStyle(settings, root_.child(0));
settings.endGroup();
}
/**
* Writes style data to a QSettings object
* @param settings The object to write to
* @param force Ignore errors
* @throw Exception
*/
void LexerStyleModel::store(QSettings& settings, bool force) const
{
if (!force && (settings.status() != QSettings::NoError))
throw new Core::Exception(tr("Failed to write style scheme"));
settings.beginGroup("EditorStyles");
settings.setValue("KScopeStyleSchemeMagic", styleMagic_);
storeStyle(settings, root_.child(0));
settings.endGroup();
}
/**
* Copies style data from another model.
* @param model The model to copy from
*/
void LexerStyleModel::copy(const LexerStyleModel& model)
{
copyStyle(root_.child(0), model.root_.child(0));
}
/**
* Uses the data stored in the model to update the style properties of all
* managed lexers.
* This method should be called after any changes are applied to the model.
*/
void LexerStyleModel::updateLexers() const
{
updateLexerStyle(root_.child(0));
}
/**
* Forces all child styles to inherit the given property.
* @param index Corresponds to a property node in the parent style
*/
void LexerStyleModel::applyInheritance(const QModelIndex& index)
{
// Ensure the index corresponds to a property node.
Node* node = nodeFromIndex(index);
if ((node == NULL) || (node->data() == NULL)
|| (node->data()->type() != PropertyNode)) {
return;
}
// Apply inheritance to child styles.
PropertyData* data = static_cast<PropertyData*>(node->data());
inheritProperty(data->value_, data->styleNode_, data->prop_, true);
}
/**
* Restores the default styles.
*/
void LexerStyleModel::resetStyles()
{
resetStyle(root_.child(0));
reset();
}
/**
* Creates an index.
* @param row The row of the index, relative to the parent
* @param column The column of the index
* @param parent The parent index.
* @return The resulting index
*/
QModelIndex LexerStyleModel::index(int row, int column,
const QModelIndex& parent) const
{
const Node* node = nodeFromIndex(parent);
if (node == NULL)
return QModelIndex();
// Root nodes do not have data.
if (node->data() == NULL)
return createIndex(row, column, (void*)node->child(row));
// Property nodes do not have children.
if (node->data()->type() == PropertyNode)
return QModelIndex();
// For column 2 on a style node, return an index representing the root
// property node.
if (column == 2) {
StyleData* style = static_cast<StyleData*>(node->data());
return createIndex(row, column, (void*)&style->propRoot_);
}
// Return an index representing a child style.
return createIndex(row, column, (void*)node->child(row));
}
/**
* Finds the parent for the given index.
* @param index The index for which the parent is needed
* @return The parent index
*/
QModelIndex LexerStyleModel::parent(const QModelIndex& index) const
{
if (!index.isValid())
return QModelIndex();
const Node* node = nodeFromIndex(index);
if (node == NULL)
return QModelIndex();
// Handle root nodes.
if (node->data() == NULL)
return QModelIndex();
// Handle top-level style nodes.
if (node->parent() == &root_)
return QModelIndex();
return createIndex(node->parent()->index(), 0, node->parent());
}
/**
* Determines the number of child indices for the given parent.
* @param parent The parent index
* @return The number of children for the index
*/
int LexerStyleModel::rowCount(const QModelIndex& parent) const
{
const Node* node = nodeFromIndex(parent);
if (node == NULL)
return 0;
// Handle root nodes.
if (node->data() == NULL)
return node->childCount();
// Property nodes have no children.
if (node->data()->type() == PropertyNode)
return 0;
// Column 2 is used for editing properties, so the number of children
// is the number of available properties.
if (parent.column() == 2) {
StyleData* data = static_cast<StyleData*>(node->data());
return data->propRoot_.childCount();
}
return node->childCount();
}
/**
* Determines the number of columns in children of the given index.
* This number is always 2.
* @param parent Ignored
* @return The number of columns for children of the index
*/
int LexerStyleModel::columnCount(const QModelIndex& parent) const
{
(void)parent;
return 2;
}
/**
* Provides the data to display/edit for a given index and role.
* @param index The index for which data is requested
* @param role The requested role
* @return The relevant data
*/
QVariant LexerStyleModel::data(const QModelIndex& index, int role) const
{
const Node* node = nodeFromIndex(index);
if (node == NULL || node->data() == NULL)
return 0;
if (node->data()->type() == StyleNode) {
// Get the lexer and style ID for this node.
StyleData* data = static_cast<StyleData*>(node->data());
QsciLexer* lexer = data->lexer_;
int style = data->style_;
switch (index.column()) {
case 0:
// Show language name or style name in the first c
没有合适的资源?快使用搜索试试~ 我知道了~
kscope-1.9.4.tar.gz
1星 需积分: 10 41 下载量 89 浏览量
2009-04-13
17:08:11
上传
评论
收藏 125KB GZ 举报
温馨提示
共140个文件
h:59个
cpp:41个
ui:14个
最新的kscope版本,在原有的基础上增加了易用性
资源详情
资源评论
资源推荐
收起资源包目录
kscope-1.9.4.tar.gz (140个子文件)
ChangeLog 2KB
config 762B
COPYING 18KB
lexerstylemodel.cpp 23KB
editorcontainer.cpp 18KB
viscintilla.cpp 17KB
mainwindow.cpp 14KB
actions.cpp 13KB
locationview.cpp 12KB
editor.cpp 10KB
locationtreemodel.cpp 10KB
config.cpp 7KB
addfilesdialog.cpp 7KB
configdialog.cpp 7KB
locationlistmodel.cpp 7KB
queryview.cpp 7KB
crossref.cpp 6KB
cscope.cpp 6KB
codebasemodel.cpp 5KB
locationmodel.cpp 5KB
stackwidget.cpp 5KB
actions.cpp 5KB
filescanner.cpp 5KB
application.cpp 4KB
session.cpp 4KB
openprojectdialog.cpp 4KB
queryresultdock.cpp 4KB
querydialog.cpp 4KB
textfilterdialog.cpp 4KB
ctags.cpp 3KB
findtextdialog.cpp 3KB
files.cpp 3KB
projectmanager.cpp 3KB
configenginesdialog.cpp 3KB
settings.cpp 3KB
projectfilesdialog.cpp 2KB
process.cpp 2KB
projectdialog.cpp 2KB
managedproject.cpp 2KB
progressbar.cpp 2KB
queryresultdialog.cpp 1KB
engineconfigwidget.cpp 1KB
configwidget.cpp 1KB
main.cpp 1KB
Doxyfile 10KB
struct.gif 1KB
variable.gif 1KB
enum.gif 1KB
function.gif 1KB
define.gif 1KB
typedef.gif 1KB
union.gif 594B
enumerator.gif 590B
member.gif 573B
cancel.gif 358B
include.gif 324B
project.h 10KB
parser.h 10KB
lexerstylemodel.h 8KB
statemachine.h 7KB
viscintilla.h 6KB
globals.h 6KB
cscope.h 6KB
engine.h 5KB
locationmodel.h 5KB
locationview.h 5KB
ctags.h 5KB
filefilter.h 4KB
queryview.h 4KB
treeitem.h 4KB
locationhistory.h 4KB
buildprogress.h 4KB
crossref.h 4KB
managedproject.h 4KB
config.h 4KB
lexerstyledelegate.h 4KB
actions.h 4KB
editor.h 3KB
editorcontainer.h 3KB
strings.h 3KB
projectdialog.h 3KB
session.h 3KB
projectmanager.h 3KB
stackwidget.h 3KB
filescanner.h 3KB
locationtreemodel.h 3KB
mainwindow.h 3KB
codebasemodel.h 3KB
locationlistmodel.h 2KB
projectconfig.h 2KB
strings.h 2KB
images.h 2KB
codebase.h 2KB
openprojectdialog.h 2KB
version.h 2KB
configdialog.h 2KB
files.h 2KB
queryresultdock.h 2KB
queryview.h 2KB
exception.h 2KB
共 140 条
- 1
- 2
qplang
- 粉丝: 0
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1