Results 1 to 2 of 2

Thread: Dialog and code design issue

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Lightbulb Dialog and code design issue

    Hello friends,
    I am porting an app not originally coded by me from Qt3 to Qt4. I am also improving the readability and design of code. While porting I came across a design issue. The problem is with the dialog whose pic is attached. It actally uses pure c++ (ported as it is from c without using signal-slot mechanism) as backend for the calculations.
    Whenever the the value in leftmost combobox(in Transmission Line Type group box) is changed there are corresponding changes. The changes include disabling or hiding of some comboboxes,linedit and labels (some rows of widgets). This results in changes in sizes of child widgets as well as dialog which I don't want to happen.
    This is achieved by using many structures which holds pointers to comboboxes, lineedits, labels.. Other than this lots of instances of layouts ,Q*Boxes,Q*GroupBoxes are used to manage this. This has really increased my problems in porting since Qt4 doen't have QVBox,QHBox,QVGroupBox,QHGroupBox forcing me to manage layouts manually.
    So, I thought I can create a widget to manage these properties,units,combo boxes and line edits in much easier way. I have attached the code for this. It works(but I haven't tested it much)
    But I think there exists a cleaner solution for this. Especially I think I can incorporate model-view design to this and make the code simpler.
    So, I request your suggestions regarding
    1. Design of dialog(placement of widget)
    2. any other qt4 widget alternatives
    3. model-view concerning this
    4. Overall design of dialog (managing availability and inavailability of widgets)

    Thanks for your time.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dialog and code design issue

    Maybe you could create a class named Value (or similar) that would represent a floating point value with an unit. Something like:
    Qt Code:
    1. class Value
    2. {
    3. public:
    4. Value( double value, const QString& unit = "" );
    5. double value() const;
    6. const QString& unit() const;
    7. ...
    8. Value convertTo( const QString& otherUnit );
    9. static QStringList units();
    10. static QStringList similarUnits( const QString& unit );dir
    11.  
    12. ...
    13. };
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. class Value
    2. {
    3. public:
    4. Value( double value, Units::Unit unit = Units::None );
    5. double value() const;
    6. Units::Unit unit() const;
    7. ...
    8. Value convertTo( Unit otherUnit );
    9. ...
    10. };
    11.  
    12.  
    13. namespace Units
    14. {
    15. enum Unit {
    16. ....
    17. };
    18. QString toString( Unit unit );
    19. QList<Unit> units();
    20. QList<Unit> similarUnits( Unit unit );
    21. ...
    22. };
    To copy to clipboard, switch view to plain text mode 
    or whatever. This should should handle information about available units and conversions between them.

    Another thing you might try is a custom widget derived from QGroupBox. Something like:
    Qt Code:
    1. class ParameterBox : public QGroupBox
    2. {
    3. ...
    4. void addParameter( const QString& label, const Value& defaultValue );
    5. void setValue( const QString& parameter, const Value& value );
    6. Value value( const QString& parameter );
    7. void setParameterEnabled( const QString& label, bool enabled );
    8. ...
    9. };
    To copy to clipboard, switch view to plain text mode 
    ParameterBox::addParameter() should add a QLabel, QLineEdit and QComboBox to a QGridLayout and populate them with data. You will also need some signals, like valueChanged( const QString& parameter, const Value& value ).

    You can also try a Parameter class, which would contain information about parameter name, its value and units, so you won't have to use parameter name and value separately. This way you can have an object that gives you a list of parameters to display and use signals and slots to handle changes. For example Parameter::valueChanged() would cause the widget to update its data and when user edits the the value you can just invoke Parameter::setValue() or Parameter::setUnit() slot.

    In Qt 4.2 there is QDataWidgetMapper. You can also write your own view widget and use a model derived from QAbstractTableModel with three columns: name, value and unit.

    There are countless possibilities.

  3. The following user says thank you to jacek for this useful post:

    Gopala Krishna (25th September 2006)

Similar Threads

  1. Replies: 3
    Last Post: 23rd July 2006, 18:02
  2. how to get code for dialog in qt4.1.2
    By quickNitin in forum Newbie
    Replies: 8
    Last Post: 8th June 2006, 14:35
  3. [QT4 & XP] QTreeView issue with Designer form
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 2nd March 2006, 17:42

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.