Abdelrazak Younes wrote:
Asger Ottar Alstrup wrote:
Investigating further, it seems that QToc::update which is called
earlier does not make any toc_models entries: The getTypes() call
returns an empty vector. From there, I can see that TocBackend::types
is empty, and this is because the TocBackend::update does not find
anything when scanning the document.
So, the question is: Where at is the best way to fix this? There is
absolutely no documentation about what types and toc_models is used
for, so I'm not sure where to fix this.
The lack of documentation is probably my fault. I will have a look at this.
I've just committed a fix:
New Revision: 15346
URL: http://www.lyx.org/trac/changeset/15346
Log:
Fix Toc dialog crash when TOC is empty.
* QToc::update(): return early if no TOC type.
* QTocDialog::updateGui(): return early of the Type model is empty and
disable the outline buttons.
Modified:
lyx-devel/trunk/src/frontends/qt4/QToc.C
lyx-devel/trunk/src/frontends/qt4/QTocDialog.C
Modified: lyx-devel/trunk/src/frontends/qt4/QToc.C
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/QToc.C?rev=15346
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/QToc.C (original)
+++ lyx-devel/trunk/src/frontends/qt4/QToc.C Mon Oct 16 10:51:55 2006
@@ -42,6 +42,9 @@
bool QToc::canOutline()
{
vector<string> const & types = getTypes();
+
+ if (types.empty())
+ return false;
BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
return ControlToc::canOutline(types[type_]);
@@ -115,6 +118,9 @@
type_ = 0;
vector<string> const & types = getTypes();
+ if (types.empty())
+ return;
+
string const & selected_type = toc::getType(params().getCmdName());
lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
Modified: lyx-devel/trunk/src/frontends/qt4/QTocDialog.C
URL:
http://www.lyx.org/trac/file/lyx-devel/trunk/src/frontends/qt4/QTocDialog.C?rev=15346
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/QTocDialog.C (original)
+++ lyx-devel/trunk/src/frontends/qt4/QTocDialog.C Mon Oct 16 10:51:55 2006
@@ -186,8 +186,17 @@
void QTocDialog::updateGui()
{
- typeCO->setModel(form_->typeModel());
- tocTV->setModel(form_->tocModel());
+ QStringListModel * type_model = form_->typeModel();
+ if (type_model->stringList().isEmpty())
+ {
+ enableButtons();
+ return;
+ }
+
+ typeCO->setModel(type_model);
+
+ if (form_->tocModel())
+ tocTV->setModel(form_->tocModel());
tocTV->showColumn(0);
// hide the pointless QHeader for now
// in the future, new columns may appear