Toc Slider fixes from Ugras Baran.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16045 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-11-25 22:16:22 +00:00
parent 07fa2456f9
commit 10dd2cbdcb
7 changed files with 40 additions and 4 deletions

View File

@ -51,6 +51,12 @@ bool QToc::canOutline()
}
int QToc::getTocDepth()
{
return toc_models_[type_]->modelDepth();
}
QStandardItemModel * QToc::tocModel()
{
lyxerr[Debug::GUI]

View File

@ -51,6 +51,8 @@ public:
void goTo(QModelIndex const & index);
///
int getType();
///
int getTocDepth();
private:

View File

@ -98,15 +98,21 @@ void QTocDialog::on_depthSL_valueChanged(int depth)
{
if (depth == depth_)
return;
setTreeDepth(depth);
}
depth_ = depth;
void QTocDialog::setTreeDepth(int depth)
{
if(depth!=-1)
depth_ = depth;
// tocTV->expandAll(); //expanding and then collapsing is probably better, but my qt 4.1.2 doesn't have expandAll()..
QModelIndexList indices =
form_->tocModel()->match(form_->tocModel()->index(0,0),
Qt::DisplayRole, "*", -1,
Qt::MatchWildcard|Qt::MatchRecursive);
Q_FOREACH (QModelIndex index, indices) { // I had to use Q_FOREACH instead of foreach
if(getIndexDepth(index) < depth) // because compile flag -DQT_NO_KEYWORDS doesn't allow me..
if(getIndexDepth(index) < depth_) // because compile flag -DQT_NO_KEYWORDS doesn't allow me..
tocTV->expand(index);
else
tocTV->collapse(index);
@ -224,6 +230,8 @@ void QTocDialog::updateGui()
enableButtons();
reconnectSelectionModel();
depthSL->setMaximum(form_->getTocDepth());
setTreeDepth();
select(form_->getCurrentIndex());
lyxerr[Debug::GUI]

View File

@ -75,6 +75,8 @@ protected:
void reconnectSelectionModel();
///
int getIndexDepth(QModelIndex const & index, int depth = -1);
///
void setTreeDepth(int depth = -1);
private:

View File

@ -24,6 +24,8 @@ using std::map;
using std::vector;
using std::string;
using std::make_pair;
using std::max;
using std::min;
namespace lyx {
namespace frontend {
@ -78,7 +80,6 @@ void TocModel::populate(Toc const & toc)
if (toc.empty())
return;
int current_row;
QModelIndex top_level_item;
@ -86,11 +87,15 @@ void TocModel::populate(Toc const & toc)
TocIterator end = toc.end();
insertColumns(0, 1);
maxdepth_ = 0;
mindepth_ = INT_MAX;
while (iter != end) {
if (iter->isValid()) {
maxdepth_ = max(maxdepth_, iter->depth());
mindepth_ = min(mindepth_, iter->depth());
current_row = rowCount();
insertRows(current_row, 1);
top_level_item = QStandardItemModel::index(current_row, 0);
@ -127,6 +132,7 @@ void TocModel::populate(TocIterator & iter,
QModelIndex const & parent)
{
int curdepth = iter->depth() + 1;
int current_row;
QModelIndex child_item;
@ -143,6 +149,8 @@ void TocModel::populate(TocIterator & iter,
return;
}
maxdepth_ = max(maxdepth_, iter->depth());
mindepth_ = min(mindepth_, iter->depth());
current_row = rowCount(parent);
insertRows(current_row, 1, parent);
child_item = QStandardItemModel::index(current_row, 0, parent);
@ -159,6 +167,11 @@ void TocModel::populate(TocIterator & iter,
}
int TocModel::modelDepth()
{
return maxdepth_ - mindepth_;
}
} // namespace frontend
} // namespace lyx

View File

@ -43,6 +43,8 @@ public:
TocIterator const tocIterator(QModelIndex const & index) const;
///
QModelIndex const modelIndex(TocIterator const & it) const;
///
int modelDepth();
private:
///
@ -59,6 +61,9 @@ private:
TocMap toc_map_;
///
ModelMap model_map_;
///
int maxdepth_;
int mindepth_;
};
} // namespace frontend

View File

@ -109,7 +109,7 @@
<number>1</number>
</property>
<property name="value" >
<number>1</number>
<number>2</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>