Results 1 to 14 of 14

Thread: QTextList constructor question

  1. #1
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QTextList constructor question

    I am working with Qt5.

    I do not see constructor for QTextList in documentation.
    Is there a reason for this?
    Can I create QTextList without parent with the new statement and then add QTextBlock-s to it. I wish to prevent destroying of list by parent Document when last block is removed.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTextList constructor question

    QTextList is an internal class used by QTextCursor in editing QTextDocument instances. You cannot create one as a standalone instance, only through use of QTextCursor.

    I think you are "confusing the map with the terrain" as they say. QTextList is set of instructions for the visual representation of a list of blocks in a document (i.e. the "map"). It is not the content of the blocks (the "terrain"). If you need to maintain the content of the blocks outside of the context of a document, then you need to implement your own data structures to do that.

  3. #3
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Ok. Thanks for replay. I was confused....
    I am forced to use QTextCursor for manipulation of QTextBlocks. I just do not understand why I am not allowed to manipulate QTextBlock directly.

    This means that Qt has no serious clases for work with complex text Just basic functions... and all those clases as QTextDocument, QTextList... and similar are not of much use for me. Not eaven for simple bullet lists.
    For what I nead I must reimplement all classes used in project and create new clases from scratch.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Quote Originally Posted by 'milimoj View Post
    This means that Qt has no serious clases for work with complex text
    It actually has, just look what even simple to use widgets like QTextBrowser can do, or QtCreator's editor views or Calligra Words.

    Cheers,
    _

  5. #5
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Ok. Then I'm missing something or I'm looking in wrong direction.
    Please, help me where to start from? I just don't see it

    What classes should I look for to implement my own widget with scene with multiple QGraphicTextItems and other graphic items on it. I clearly can see how to implement that when I have only one QGraphictextitems, but when I wanth to use more then one item in scene everything goes to hell.

    For instance what clases to start from for my first question: to create multilayer numerized bullet list that propagates numbering through all items in scene an to be able to catch when text blocks in any of lists in any of documents are changed, removed, moved, added, inserted... to list... so I can refresh numeration. I just don't see anything that can help me. What class to use to controll QTextBlocks in more then one QGraphictextitems?
    Can I use some standard Qt class for bullets and numbering or I must insert symbols to text by my self and control them, and what to use to insert graphic symbols (I guess some QFrames.... with bullets or e.g. 1.1.2. text ) in front of text in block.

    Example:

    Document 1:

    1. Text something...
    1.1.2 Some nested text
    ....
    ....

    Document 2:

    2. Text somenting 2
    2.1 Nested text in 2
    .....

    I know I'm boring but I am stuck with this and documentation and examples are hard to find for this case.

    Thanks, for help

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Quote Originally Posted by 'milimoj View Post
    Please, help me where to start from?
    If the documentation or examples doesn't cover something, the source of Qt itself an numerous FOSS projects using Qt are available for studying.

    Quote Originally Posted by 'milimoj View Post
    For instance what clases to start from for my first question: to create multilayer numerized bullet list that propagates numbering through all items in scene an to be able to catch when text blocks in any of lists in any of documents are changed, removed, moved, added, inserted... to list... so I can refresh numeration.
    Your first question was why there is no constructor in QTextList.
    For that new question you could look into modelling the data in a list or tree and displaying each item.

    Quote Originally Posted by 'milimoj View Post
    What class to use to controll QTextBlocks in more then one QGraphictextitems?
    Most classes can have multiple instances. If you find a class that allows you to manipulate text in one graphics item, the same should be true for any other text item.

    Cheers,
    _

  7. #7
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Yes. We have pushed the subject to my question from other post. Sorry for that, but this is interesting subject.... at least for me and I have a headache because of it.

    Ok. I had idea of creating a tree of my own classes too but I do not understand how to keep list of "some kind of pointers" to paragraphs (I must be abale to catch when someone change something in paragraph in any of documents on scene - as I need to prevent deleting og bullet simbols, update numbering...). As I understood QTextBlock objects does not exists all the time. They are created when neaded for representation of information about paragraph (- correct me if I am wrong, please -) and I can not keep pointers to these objects. Is there any class object that represent paragraph that is always accesable and can be reimplemented.

    Only thing I could think of is to create QTextBlockGroup in each of Documents on scene and to keep pointers to them in my class outside the documents. Then, I should use connections to blockRemoved, blockInserted... signals from QTextBlockGroup-s.... But this semas to be very ugly programming. Is there some other way?

    Thanks for your patience, again

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    What part of your application is using the QTextDocument API to change the data?
    Can't you just add signalling there?

    Cheers,
    _

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextList constructor question

    Quote Originally Posted by 'milimoj View Post
    Ok. I had idea of creating a tree of my own classes too but I do not understand how to keep list of "some kind of pointers" to paragraphs
    There is no need to develop your own set of classes. The problem is not here -- QTextDocument and family is a set of classes for keeping the data related to text documents and you can extend it with your own subclasses. Your problem seems to rather be with rendering. Thus it seems likely that you should implement a custom text layout engine (see QAbstractTextDocumentLayout) which uses existing QTextDocument infrastructure.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Quote Originally Posted by anda_skoa View Post
    What part of your application is using the QTextDocument API to change the data?
    Can't you just add signalling there?

    Cheers,
    _
    Yes I can. Problem is that I must use some of existing clases for textblock control in QTextDocument and then again catch signals in some extern class to provide "real" logic for text parsing. In the end this will be my solution. That should work but solution is "ugly" for my taste.
    If only there was some class similar to QTextBlock with signals it would be easier and much less coding.


    @wysota
    Thanks for replay. I will take a look in QAbstractTextDocumentLayout documentation, but code is already present and I'm not sure if I'll be able to change it much. I just wanted to add bullet list functionality to it, with nesting of numbering lists.

  11. #11
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Quote Originally Posted by wysota View Post
    There is no need to develop your own set of classes. The problem is not here -- QTextDocument and family is a set of classes for keeping the data related to text documents and you can extend it with your own subclasses. Your problem seems to rather be with rendering. Thus it seems likely that you should implement a custom text layout engine (see QAbstractTextDocumentLayout) which uses existing QTextDocument infrastructure.
    You are right. I have looked at the QAbstractTextDocumentLayout documentation and it seams that I should implement my own TextList class which will return desired textItems and reimplement QAbstractTextDocumentLayout. But, if I was confused with relations between QTextDocument and QGraphicTextItem then I'm lost here. From source code it seams like I must use something like my own drawListItem method in QAbstractTextDocumentLayout for drawing list items, but that is part of QTextDocumentLayoutPrivate and I can't reimplement it. How should I do this? As I can see there are only few virtual methods in QAbstractTextDocumentLayout.
    Last edited by 'milimoj; 28th May 2015 at 12:08.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextList constructor question

    QTextObjectInterface for each object type will provide a method for rendering that object in the document.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    Ok.

    1. I have to create my own class similar to QTextList, which will take care of QTextBlocks added into list and about list style, indent.... That class should be reimplemented QTextBlockGroup and QTextObjectInterface .
    2. Then I should implement drawObject(...) of that class where I would draw some bullet characters in front of selected QTextBlock (like in drawListItem() from QTextDocumentLayoutPrivate) and add selected blocks into QTextBlockGroup.
    3. On the end register that class as handler for my object type in document constructor.

    4. Now.... When "create bullet list" button is triggered how I should activate that drawObject, and how to call it again to re-draw bullet character when text from text block is moved, deleted....?
    I do not see how I should redraw all bullets in list when block is deleted, and how to prevent editing of bullet characters from application (e.g. inserting SPACE-s before bullet symbol).
    Also, how to delete bullets when "create bullet list" button is toggled to off if bullets are edited?

    This approach still seams wrong to me. As I can see in QTextDocumentLayout source code, bullet drawing is called from drawBlock function.
    Last edited by 'milimoj; 28th May 2015 at 16:03.

  14. #14
    Join Date
    May 2015
    Posts
    21
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTextList constructor question

    @wysota
    Thanks for help. QTextObjectInterface was right choice. It is not easy to implement all functionality I need but it is the correct way to do it. I had to do a lot of coding but this seams to be a solution I need.

    I must notice few things here :

    1. Documentation for Qt is really bad. There should be more examples, especially for more complex usage. I had to look a lot of code examples on the net and still could not find examples of how to use all functions from class in the way they could be used.
    We need more instructions about what will happen when some parameter is set, changed.... What signals shall be emited... Who will take the control... What fields in view shall be repainted... I had to read dozens of pages just to use one function from class, because in class documentation I found only few words about that functions. Please add tabs for more explanation and examples in documentation.

    2. It seems that a too little new functionality are added to existing classes with new releases of Qt. All of this job could be done in few minutes if only QTextList class had function for setStartValue(int), which seems to be so natural. In fact I took a look in source code of QTextDocumentLayout and QTextList and souch expansion is a trivial job. Just one offset to add when counting index if block in list.

    Again, thanks for help

Similar Threads

  1. Inserting QTextList into QTextDocument
    By ToddAtWSU in forum Qt Programming
    Replies: 0
    Last Post: 20th September 2013, 15:55
  2. QPainter Constructor Syntax Question
    By deejross in forum Newbie
    Replies: 6
    Last Post: 26th January 2011, 02:16
  3. qglwidget and constructor question on mac
    By john_god in forum Qt Programming
    Replies: 0
    Last Post: 17th June 2010, 01:51
  4. QtScript: default constructor question
    By QPlace in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2009, 20:36
  5. Replies: 0
    Last Post: 31st May 2009, 17:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.