}
+TocModel::TocModel(QObject * parent)
+ : model_(new TocTypeModel(parent)),
+ sorted_model_(new QSortFilterProxyModel(parent)),
+ is_sorted_(false), maxdepth_(0), mindepth_(0)
+{
+#if QT_VERSION >= 0x040300
+ sorted_model_->setSortLocaleAware(true);
+#endif
+ sorted_model_->setSourceModel(model_);
+}
+
+
+QAbstractItemModel * TocModel::model()
+{
+ if (is_sorted_)
+ return sorted_model_;
+ return model_;
+}
+
+
+QAbstractItemModel const * TocModel::model() const
+{
+ if (is_sorted_)
+ return sorted_model_;
+ return model_;
+}
+
+
+void TocModel::clear()
+{
+ model_->blockSignals(true);
+ model_->clear();
+ model_->blockSignals(false);
+}
+
+
+void TocModel::sort(bool sort_it)
+{
+ is_sorted_ = sort_it;
+ if (is_sorted_)
+ sorted_model_->sort(0);
+}
+
TocItem const & TocModel::tocItem(QModelIndex const & index) const
{
- return (*toc_)[data(index, Qt::UserRole).toUInt()];
+ return (*toc_)[model()->data(index, Qt::UserRole).toUInt()];
}
unsigned int const toc_index = toc_->item(dit) - toc_->begin();
- QModelIndexList list = match(index(0, 0), Qt::UserRole,
+ QModelIndexList list = model()->match(model()->index(0, 0), Qt::UserRole,
QVariant(toc_index), 1,
Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive));
}
-TocModel::TocModel(QObject * parent): QStandardItemModel(parent),
- maxdepth_(0), mindepth_(0)
-{
-}
-
-
void TocModel::reset()
{
- QStandardItemModel::reset();
+ model_->reset();
}
return;
}
- blockSignals(true);
+ model_->blockSignals(true);
int current_row;
QModelIndex top_level_item;
- insertColumns(0, 1);
+ model_->insertColumns(0, 1);
maxdepth_ = 0;
mindepth_ = INT_MAX;
TocItem const & item = (*toc_)[index];
maxdepth_ = max(maxdepth_, item.depth());
mindepth_ = min(mindepth_, item.depth());
- current_row = rowCount();
- insertRows(current_row, 1);
- top_level_item = QStandardItemModel::index(current_row, 0);
- setData(top_level_item, toqstr(item.str()), Qt::DisplayRole);
- setData(top_level_item, index, Qt::UserRole);
+ current_row = model_->rowCount();
+ model_->insertRows(current_row, 1);
+ top_level_item = model_->index(current_row, 0);
+ model_->setData(top_level_item, toqstr(item.str()), Qt::DisplayRole);
+ model_->setData(top_level_item, index, Qt::UserRole);
LYXERR(Debug::GUI, "Toc: at depth " << item.depth()
<< ", added item " << item.str());
break;
}
- setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
- blockSignals(false);
+ model_->setHeaderData(0, Qt::Horizontal, QVariant("title"), Qt::DisplayRole);
+ if (is_sorted_)
+ sorted_model_->sort(0);
+ model_->blockSignals(false);
reset();
// emit headerDataChanged();
}
int current_row;
QModelIndex child_item;
- insertColumns(0, 1, parent);
+ model_->insertColumns(0, 1, parent);
size_t end = toc_->size();
++index;
}
maxdepth_ = max(maxdepth_, item.depth());
mindepth_ = min(mindepth_, item.depth());
- current_row = rowCount(parent);
- insertRows(current_row, 1, parent);
- child_item = QStandardItemModel::index(current_row, 0, parent);
- setData(child_item, toqstr(item.str()), Qt::DisplayRole);
- setData(child_item, index, Qt::UserRole);
+ current_row = model_->rowCount(parent);
+ model_->insertRows(current_row, 1, parent);
+ child_item = model_->index(current_row, 0, parent);
+ model_->setData(child_item, toqstr(item.str()), Qt::DisplayRole);
+ model_->setData(child_item, index, Qt::UserRole);
populate(index, child_item);
if (index >= end)
break;
names_->clear();
names_->blockSignals(false);
iterator end = models_.end();
- for (iterator it = models_.begin(); it != end; ++it) {
- it.value()->blockSignals(true);
+ for (iterator it = models_.begin(); it != end; ++it)
it.value()->clear();
- it.value()->blockSignals(false);
- }
}
}
-QStandardItemModel * TocModels::model(QString const & type)
+QAbstractItemModel * TocModels::model(QString const & type)
{
if (!bv_)
return 0;
iterator it = models_.find(type);
if (it != models_.end())
- return it.value();
+ return it.value()->model();
LYXERR0("type not found: " << type);
return 0;
}
LYXERR(Debug::GUI, "TocModels::goTo(): QModelIndex is invalid!");
return;
}
- LASSERT(index.model() == it.value(), return);
+ LASSERT(index.model() == it.value()->model(), return);
TocItem const item = it.value()->tocItem(index);
LYXERR(Debug::GUI, "TocModels::goTo " << item.str());
dispatch(item.action());
}
+bool TocModels::isSorted(QString const & type) const
+{
+ const_iterator it = models_.find(type);
+ if (it == models_.end()) {
+ LYXERR0("type not found: " << type);
+ return false;
+ }
+ return it.value()->isSorted();
+}
+
+
+void TocModels::sort(QString const & type, bool sort_it)
+{
+ iterator it = models_.find(type);
+ if (it == models_.end())
+ LYXERR0("type not found: " << type);
+ else
+ it.value()->sort(sort_it);
+}
+
} // namespace frontend
} // namespace lyx
#include <QHash>
#include <QList>
+#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStringList>
-class QAbstractItemModel;
-class QSortFilterProxyModel;
-
namespace lyx {
class Buffer;
};
-class TocModel : public QStandardItemModel
+class TocModel
{
public:
///
///
void reset();
///
+ void clear();
+ ///
+ QAbstractItemModel * model();
+ ///
+ QAbstractItemModel const * model() const;
+ ///
+ void sort(bool sort_it);
+ ///
+ bool isSorted() const { return is_sorted_; }
+ ///
TocItem const & tocItem(QModelIndex const & index) const;
///
QModelIndex modelIndex(DocIterator const & dit) const;
///
void populate(unsigned int & index, QModelIndex const & parent);
///
+ TocTypeModel * model_;
+ ///
+ QSortFilterProxyModel * sorted_model_;
+ ///
+ bool is_sorted_;
+ ///
QList<QModelIndex> toc_indexes_;
///
Toc const * toc_;
///
int depth(QString const & type);
///
- QStandardItemModel * model(QString const & type);
+ QAbstractItemModel * model(QString const & type);
///
QAbstractItemModel * nameModel();
///
void init(Buffer const & buffer);
///
void updateBackend() const;
+ ///
+ void sort(QString const & type, bool sort_it);
+ ///
+ bool isSorted(QString const & type) const;
Q_SIGNALS:
/// Signal that the internal toc_models_ has been reset.
}
+void TocWidget::on_sortCB_stateChanged(int state)
+{
+ gui_view_.tocModels().sort(current_type_, state == Qt::Checked);
+ updateView();
+}
+
/* FIXME (Ugras 17/11/06):
I have implemented a indexDepth function to get the model indices. In my
opinion, somebody should derive a new qvariant class for tocModelItem
void TocWidget::enableControls(bool enable)
{
updateTB->setEnabled(enable);
+ sortCB->setEnabled(enable);
if (!canOutline(current_type_))
enable = false;
typeCO->setEnabled(true);
tocTV->setEnabled(true);
- QStandardItemModel * toc_model = gui_view_.tocModels().model(current_type_);
+ QAbstractItemModel * toc_model = gui_view_.tocModels().model(current_type_);
if (tocTV->model() != toc_model) {
tocTV->setModel(toc_model);
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
+
+ sortCB->blockSignals(true);
+ sortCB->setChecked(gui_view_.tocModels().isSorted(current_type_));
+ sortCB->blockSignals(false);
+
bool controls_enabled = toc_model && toc_model->rowCount() > 0
&& !gui_view_.buffer()->isReadonly();
enableControls(controls_enabled);
void on_tocTV_activated(QModelIndex const &);
void on_tocTV_clicked(QModelIndex const &);
void on_updateTB_clicked();
+ void on_sortCB_stateChanged(int state);
void on_depthSL_valueChanged(int depth);
void on_typeCO_currentIndexChanged(int value);
void on_moveUpTB_clicked();
<x>0</x>
<y>0</y>
<width>185</width>
- <height>250</height>
+ <height>184</height>
</rect>
</property>
<property name="windowTitle" >
<string/>
</property>
- <layout class="QGridLayout" >
- <property name="margin" >
- <number>9</number>
- </property>
- <property name="spacing" >
- <number>6</number>
- </property>
- <item row="1" column="0" >
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" colspan="4" >
+ <widget class="QComboBox" name="typeCO" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Ignored" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Switch between available lists (table of contents, list of figures, list of tables, and others)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="4" >
<widget class="QTreeView" name="tocTV" >
<property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>13</hsizetype>
- <vsizetype>7</vsizetype>
+ <sizepolicy vsizetype="Expanding" hsizetype="Ignored" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
- <item row="3" column="0" >
+ <item row="3" column="0" colspan="4" >
<layout class="QHBoxLayout" >
- <property name="margin" >
- <number>0</number>
- </property>
<property name="spacing" >
<number>6</number>
</property>
+ <property name="margin" >
+ <number>0</number>
+ </property>
<item>
<widget class="QToolButton" name="updateTB" >
<property name="toolTip" >
<string>...</string>
</property>
<property name="icon" >
- <iconset>../../../../lib/images/reload.png</iconset>
+ <iconset>
+ <normaloff>../../../../lib/images/reload.png</normaloff>../../../../lib/images/reload.png</iconset>
</property>
<property name="iconSize" >
<size>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" >
+ <property name="sizeHint" stdset="0" >
<size>
<width>16</width>
<height>20</height>
<string>...</string>
</property>
<property name="icon" >
- <iconset>../../../../lib/images/promote.png</iconset>
+ <iconset>
+ <normaloff>../../../../lib/images/promote.png</normaloff>../../../../lib/images/promote.png</iconset>
</property>
<property name="iconSize" >
<size>
<string>...</string>
</property>
<property name="icon" >
- <iconset>../../../../lib/images/demote.png</iconset>
+ <iconset>
+ <normaloff>../../../../lib/images/demote.png</normaloff>../../../../lib/images/demote.png</iconset>
</property>
<property name="iconSize" >
<size>
<string>...</string>
</property>
<property name="icon" >
- <iconset>../../../../lib/images/down.png</iconset>
+ <iconset>
+ <normaloff>../../../../lib/images/down.png</normaloff>../../../../lib/images/down.png</iconset>
</property>
<property name="iconSize" >
<size>
<string>...</string>
</property>
<property name="icon" >
- <iconset>../../../../lib/images/up.png</iconset>
+ <iconset>
+ <normaloff>../../../../lib/images/up.png</normaloff>../../../../lib/images/up.png</iconset>
</property>
<property name="iconSize" >
<size>
</item>
</layout>
</item>
- <item row="0" column="0" >
- <widget class="QComboBox" name="typeCO" >
- <property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>13</hsizetype>
- <vsizetype>0</vsizetype>
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="toolTip" >
- <string>Switch between available lists (table of contents, list of figures, list of tables, and others)</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
+ <item row="2" column="0" colspan="3" >
<widget class="QSlider" name="depthSL" >
<property name="sizePolicy" >
- <sizepolicy>
- <hsizetype>13</hsizetype>
- <vsizetype>0</vsizetype>
+ <sizepolicy vsizetype="Fixed" hsizetype="Ignored" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
+ <item row="2" column="3" >
+ <widget class="QCheckBox" name="sortCB" >
+ <property name="text" >
+ <string>Sort</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<tabstops>
<tabstop>typeCO</tabstop>
<tabstop>tocTV</tabstop>
- <tabstop>depthSL</tabstop>
</tabstops>
<includes>
<include location="local" >qt_i18n.h</include>