I need some advice about custom models. My only experience is using QTableWidget so this model/view stuff is new to me. I'm currently using Qt 4.3.4 on Windows XP.

My application is designed to configure network devices. From an outside source, it receives data for each device found on the network. Some of this data is to be displayed in tables (some of the displayed data is to be editable). The application will have a QTabWidget for each type of device and a tab to display all devices found. Each tab will display a table containing a subset of it's data.

Issue: The base table will show only the common data for each device found. The other 2 device-specific tables will show the common data plus some device-specific data.

Example:
  • Type-A table will display:
    • Name
    • SubType
    • IP Address
    • Port1 Value
    • Port2 Value

  • Type-B table will display:
    • Name
    • SubType
    • IP Address
    • Group ID

  • Base table will display all Type-A and all Type-B devices:
    • Name
    • SubType
    • IP Address

My data sets are something like this:

Qt Code:
  1. class CBaseData
  2. {
  3. public:
  4. CBaseData( int nDevType );
  5. virtual ~CBaseData( void );
  6.  
  7. // Accessors
  8. QString GetDeviceName( void ) { return m_sName; }
  9. void SetDeviceName( QString sName );
  10.  
  11. bool IsDynamicIP( void ) { return m_bIsDynamicIP; }
  12. uint1 GetIPMode( void ) { return m_bIsDynamicIP ? 1 : 0; }
  13. void SetIPMode( bool bIsDynamic ) { m_bIsDynamicIP = bIsDynamic; }
  14.  
  15. int GetDevType( void ) { return m_nDevType; }
  16. void SetDevType( int nDevType ) { m_nDevType = nDevType; }
  17.  
  18. QString GetID( void ) { return m_sID; }
  19. void SetID( QString sID ) { m_sCID = sID; }
  20.  
  21. QString GetIPAddr( void ) { return m_sIPAddr; }
  22. void SetIPAddr( QString sIPAddr ) { m_sIPAddr = sIPAddr; }
  23.  
  24. QString GetSubNetMask( void ) { return m_sSubNetMask; }
  25. void SetSubNetMask( QString sMask ) { m_sSubNetMask = sMask; }
  26.  
  27. QString GetDefIP( void ) { return m_sDefIP; }
  28. void SetDefIP( QString sDefIP ) { m_sDefIP = sDefIP; }
  29.  
  30. QString GetModelName( void ) { return m_sModelName; }
  31. void SetModelName( QString sName );
  32.  
  33. QString GetSerialNum( void ) { return m_sSerialNum; }
  34. void SetSerialNum( QString sSerialNum );
  35.  
  36. QString GetHWVer( void ) { return m_sHardwareVer; }
  37. void SetHWVer( QString sVersion );
  38.  
  39. QString GetSWVer( void ) { return m_sSoftwareVer; }
  40. void SetSWVer( QString sVersion );
  41.  
  42. protected:
  43. int m_nDevType; // Device Type
  44. bool m_bIsDynamicIP; // Static or dynamic IP address
  45. QString m_sID; // Device ID
  46. uint4 m_sIPAddr; // IP address of device
  47. uint4 m_sSubNetMask; // Subnet Mask of device
  48. uint4 m_sDefIP; // Default IP address of device
  49. QString m_sName; // Name of device
  50. QString m_sModelName; // Manufacturer model name for this device (read-only)
  51. QString m_sSerialNum; // Device serial number
  52. QString m_sHardwareVer; // Hardware version number (read-only)
  53. QString m_sSoftwareVer; // Application software version number (read-only)
  54. // ... extra network connection data
  55.  
  56. };
  57.  
  58. class CTypeAData : public CBaseData
  59. {
  60. public:
  61. CTypeAData( int nDevType );
  62. virtual ~CTypeAData( void );
  63.  
  64. // Accessors
  65. uint4 GetPort1Num( void ) { return m_nPort1Num; }
  66. void SetPort1Num( uint4 nNum ) { m_nPort1Num = nNum; }
  67.  
  68. uint4 GetPort2Num( void ) { return m_nPort2Num; }
  69. void SetPort2Num( uint4 nNum ) { m_nPort2Num = nNum; }
  70.  
  71. protected:
  72. uint4 m_nPort1Num; // value for port 1
  73. uint4 m_nPort2Num; // value for port 2
  74. // ...extra private data
  75. };
  76.  
  77. class CTypeBData : public CBaseData
  78. {
  79. public:
  80. CTypeBData( void );
  81. virtual ~CTypeBData( void );
  82.  
  83. // Accessors
  84. uint1 GetGroupID( void ) { return m_nGrpID; }
  85. void SetGroupID( const uint1 nID ) { m_nGrpID = nID; }
  86.  
  87. protected:
  88. uint1 m_nSMPTEGrpID; // Group ID - R/W
  89. // ...extra private data
  90. };
To copy to clipboard, switch view to plain text mode 

As you can see, each data class seems to map nicely to a device/table. My problem is deciding the model(s) to choose.

I would like to use QAbstractTableModel as the parent of a custom model. Because I'm dealing with different data sets it seems like I will need a separate model for each table BUT I don't want to duplicate any code for the the Base table model.

Possibilities (please note that I'm just exploring here):
  1. Keep a data pointer to each type of data in my custom model. Somehow determine which device type is required for model function calls.
  2. Create a separate model for each data type. (How to handle the Base data table?)
  3. Create a 'base' model and use that as a parent for custom Type-A and Type-B models. (Can this even be done?)
  4. Any other possibilities out there?